Current context for LoopBack applications, based on node-continuation-local-storage.
- Add
per-request-context
middleware to yourserver/middleware-config.json
:
{
"initial": {
"loopback-context-cls#per-request-context": {
}
}
}
- Then you can access the context from your code:
var ClsContext = require('loopback-context-cls');
// ...
MyModel.myMethod = function(cb) {
var ctx = ClsContext.getCurrentContext();
ctx.get('key');
ctx.set('key', { foo: 'bar' });
});
See also https://docs.strongloop.com/display/APIC/Using+current+context