moleculer-web
Advanced tools
Changelog
0.8.5 (2018-11-28)
<a name="0.8.4"></a>
Changelog
0.8.4 (2018-11-18)
req.url
, add req.originalUrl
and req.baseUrl
for better middleware support (e.g. support static serving in subpath).<a name="0.8.3"></a>
Changelog
0.8.3 (2018-11-11)
Promise
in started
& stopped
handlers.log4XXResponses
setting.<a name="0.8.2"></a>
Changelog
0.8.2 (2018-10-04)
authenticate
method.This authenticate
method is similar to authorize
. You have access to req
, res
and route
objects and you can authenticate the user from the request.
The returned data is saved to the ctx.meta.user
. To enable this logic set authentication: true
in route options.
Example
module.exports = {
name: "api",
mixins: [ApiGatewayService],
settings: {
routes: [
{
// Enable authentication
authentication: true
}
]
},
methods: {
authenticate(ctx, route, req, res) {
let accessToken = req.query["access_token"];
if (accessToken) {
if (accessToken === "12345") {
return Promise.resolve({ id: 1, username: "john.doe", name: "John Doe" });
} else {
return Promise.reject();
}
} else {
return Promise.resolve(null);
}
}
}
});
.npmignore
<a name="0.8.1"></a>
Changelog
0.8.1 (2018-08-04)
<a name="0.8.0"></a>
Changelog
0.8.0 (2018-07-08)
onAfterCall
hook has changedIn previous versions of Moleculer Web, you couldn't manipulate the data
in onAfterCall
. Now you can, but you must always return the new or original data
.
Modify only headers
broker.createService(ApiGatewayService, {
settings: {
routes: [{
onAfterCall(ctx, route, req, res, data) {
res.setHeader("X-Custom-Header", "123456");
// Must return the original `data`
return data;
}
}]
}
});
Modify (wrap) the original data
broker.createService(ApiGatewayService, {
settings: {
routes: [{
onAfterCall(ctx, route, req, res, data) {
// Wrap the original data to a new object
return {
other: "things",
data: data
};
}
}]
}
});
The onBeforeCall
and authorize
hooks are called before custom alias functions too.
And you have access to Context as req.$ctx
or res.$ctx
In early versions the *
match string is enabled to call all services & actions. The matcher changed, in new versions use the **
(double star) match string for the same function.