3aeee7dbe4
Start 3.x + drop support for Node v0.10/v0.12 |
||
---|---|---|
browser | ||
server | ||
test | ||
.eslintignore | ||
.eslintrc | ||
.gitignore | ||
.travis.yml | ||
CHANGES.md | ||
CONTRIBUTING.md | ||
README.md | ||
package.json |
README.md
loopback-context
Current context for LoopBack applications, based on node-continuation-local-storage.
WARNING
We recommend AGAINST using the loopback-context module until there is a stable solution to the issue below!
The module node-continuation-local-storage is known to have many problems, see e.g. issue #59. As a result, loopback-context does not work in many situations, as can be seen from issues reported in LoopBack's issue tracker.
If you are running on Node v6, you can try the new alternative cls-hooked.
Usage
- Add
per-request
middleware to yourserver/middleware-config.json
:
{
"initial": {
"loopback-context#per-request": {
}
}
}
- 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 the official LoopBack documentation for more details.