1f214bf3ba
As soon as CLS module is loaded, the instrumentation/patching of async-listener is fired. This may cause stack overflows due to promise instrumentation. By loading CLS module lazily (only when used for real), we avoid this kind of problems in applications that are not using current-context at all. |
||
---|---|---|
browser | ||
server | ||
test | ||
.eslintignore | ||
.eslintrc | ||
.gitignore | ||
CONTRIBUTING.md | ||
README.md | ||
package.json |
README.md
loopback-context
Current context for LoopBack applications, based on node-continuation-local-storage.
Usage
- Add
per-request-context
middleware to yourserver/middleware-config.json
:
{
"initial": {
"loopback-context#per-request-context": {
}
}
}
- Then you can access the context from your code:
var LoopBackContext = require('loopback-context');
// ...
MyModel.myMethod = function(cb) {
var ctx = LoopBackContext.getCurrentContext();
ctx.get('key');
ctx.set('key', { foo: 'bar' });
});
See also https://docs.strongloop.com/display/APIC/Using+current+context