-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master-moleculer' into middlewares-d-ts
# Conflicts: # index.d.ts
- Loading branch information
Showing
2 changed files
with
216 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const ServiceBroker = require("../src/service-broker"); | ||
|
||
const broker = new ServiceBroker({ | ||
middlewares: [ | ||
{ | ||
call(next) { | ||
return (actionName, params, opts) => { | ||
const p = next(actionName, params, opts); | ||
|
||
const pp = p.then(res => { | ||
return res; | ||
}); | ||
|
||
pp.ctx = p.ctx; | ||
|
||
return pp; | ||
}; | ||
} | ||
} | ||
] | ||
}); | ||
|
||
broker.createService({ | ||
name: "statusCodeTest", | ||
|
||
actions: { | ||
testNotFound: { | ||
rest: "GET /testNotFound", | ||
handler(ctx) { | ||
ctx.meta.$statusCode = 404; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
broker.createService({ | ||
name: "test", | ||
actions: { | ||
hello: { | ||
async handler(ctx) { | ||
await ctx.call("statusCodeTest.testNotFound"); | ||
this.logger.info("Context meta", ctx.meta); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
broker.start().then(() => { | ||
broker.repl(); | ||
|
||
broker.call("test.hello").then(res => { | ||
console.log("Result:", res); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters