Blame view
node_modules/loopback-context/README.md
1.2 KB
f7563de62
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# loopback-context Current context for LoopBack applications, based on node-continuation-local-storage. ## WARNING The module node-continuation-local-storage is known to have many problems, see e.g. [issue #59](https://github.com/othiym23/node-continuation-local-storage/issues/59). As a result, loopback-context does not work in many situations, as can be seen from issues reported in LoopBack's [issue tracker](https://github.com/strongloop/loopback/issues?utf8=%E2%9C%93&q=is%3Aissue%20getCurrentcontext). **We recommend AGAINST using this module.** If you are running on Node v6, you can try the new alternative [cls-hooked](https://github.com/Jeff-Lewis/cls-hooked). ## Usage 1) Add `per-request` middleware to your `server/middleware-config.json`: ```json { "initial": { "loopback-context#per-request": { } } } ``` 2) Then you can access the context from your code: ```js 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](https://docs.strongloop.com/display/APIC/Using+current+context) for more details. |