Current context for LoopBack applications, based on node-continuation-local-storage
Go to file
Miroslav Bajtoš 3aeee7dbe4 Merge pull request #14 from strongloop/next-major-drop-old-node
Start 3.x + drop support for Node v0.10/v0.12
2016-11-22 09:01:07 +01:00
browser Rename to loopback-context/LoopBackContext 2016-07-29 09:36:34 +02:00
server API cleanup 2016-08-01 15:23:19 +02:00
test API cleanup 2016-08-01 15:23:19 +02:00
.eslintignore Initial commit 2016-07-28 15:11:12 +02:00
.eslintrc Initial commit 2016-07-28 15:11:12 +02:00
.gitignore Initial commit 2016-07-28 15:11:12 +02:00
.travis.yml Enable Travis CI 2016-08-01 14:40:22 +02:00
CHANGES.md 1.0.0 2016-08-10 10:46:08 +02:00
CONTRIBUTING.md Initial commit 2016-07-28 15:11:12 +02:00
README.md make warning less ambigious 2016-08-10 14:16:21 +02:00
package.json Drop support for Node v0.10 and v0.12 2016-11-19 02:27:54 -08:00

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

  1. Add per-request middleware to your server/middleware-config.json:
{
  "initial": {
    "loopback-context#per-request": {
    }
  }
}
  1. 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.