Current context for LoopBack applications, based on node-continuation-local-storage
Go to file
Miroslav Bajtoš 9bd4afbe7e Initial implementation 2016-07-29 09:17:04 +02:00
browser Initial implementation 2016-07-29 09:17:04 +02:00
server Initial implementation 2016-07-29 09:17:04 +02:00
test Initial implementation 2016-07-29 09:17:04 +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
CONTRIBUTING.md Initial commit 2016-07-28 15:11:12 +02:00
README.md Initial implementation 2016-07-29 09:17:04 +02:00
package.json Initial implementation 2016-07-29 09:17:04 +02:00

README.md

loopback-context-cls

Current context for LoopBack applications, based on node-continuation-local-storage.

Usage

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