moleculer-web
Advanced tools
Changelog
0.3.0 (2017-06-01)
It is possible to use named parameters in aliases. Named paramters are defined by prefixing a colon to the parameter name (:name
)
Usage
broker.createService(ApiGatewayService, {
settings: {
routes: [{
path: "/api",
aliases: {
"GET greeter/:name": "test.greeter",
"optinal-param/:name?": "test.echo",
"repeat-param/:args*": "test.echo",
"GET /": "test.hello"
}
}]
}
});
// Start server
broker.start();
Example: examples/full
<a name="0.2.2"></a>
Changelog
0.2.2 (2017-06-01)
The route of service has onBeforeCall
and onAfterCall
hooks. It can be asynchronous if return with Promise. In methods the this
is pointed to Service instance. So you can access the service methods & broker.
Usage
broker.createService(ApiGatewayService, {
settings: {
routes: [{
// Call before `broker.call`
onBeforeCall(ctx, route, req, res) {
// Save request headers to context meta
ctx.meta.userAgent = req.headers["user-agent"];
},
// Call after `broker.call` and before send back the response
onAfterCall(ctx, route, req, res, data) {
res.setHeader("X-Custom-Header", "123456");
}
}]
}
});
// Start server
broker.start();
Example: examples/full
<a name="0.2.1"></a>
Changelog
0.2.1 (2017-05-23)
You can use Moleculer-Web as a middleware for ExpressJS.
Usage
const svc = broker.createService(ApiGatewayService, {
settings: {
middleware: true
}
});
// Create Express application
const app = express();
// Use ApiGateway as middleware
app.use("/api", svc.express());
// Listening
app.listen(3000);
// Start server
broker.start();
Example: examples/express
<a name="0.2.0"></a>
Changelog
0.2.0 (2017-05-09)
For more information check the full or authorization examples or readme
<a name="0.2.0"></a>