I have my middlewares configured in Strongloop in the following way in middleware.json:
{
"initial:before": {
"loopback#favicon": {}
},
"initial": {
"compression": {},
"cors": {
"params": {
"origin": true,
"credentials": true,
"maxAge": 86400
}
},
"helmet#xssFilter": {},
"helmet#frameguard": {
"params": [
"deny"
]
},
"helmet#hsts": {
"params": {
"maxAge": 0,
"includeSubdomains": true
}
},
"helmet#hidePoweredBy": {},
"helmet#ieNoOpen": {},
"helmet#noSniff": {},
"helmet#noCache": {
"enabled": false
},
"express-jwt": {
"paths": [
"${restApiRoot}"
],
"params": {
"secret": "secret"
}
}
},
"session": {},
"auth": {
"./middleware/token-validation": {
"paths": [
"${restApiRoot}"
]
}
},
"parse": {},
"routes": {
"loopback#rest": {
"paths": [
"${restApiRoot}"
]
}
},
"files": {},
"final": {
"loopback#urlNotFound": {}
},
"final:after": {
"loopback#errorHandler": {}
}
}
This file was genereated by Strongloop, except the "auth" middleware was added manually. In this middleware (token-validation.js) I want to access the currentContext like this:
return function tokenValidation(req, res, next) {
var app = req.app;
var ctx = app.loopback.getCurrentContext();
console.log(ctx);
});
However, the ctx object is always null.... Any ideas?