Current context for LoopBack applications, based on node-continuation-local-storage
Go to file
josieusa 518aedc89f Use cls-hooked instead of continuation-local-storage,
as suggested by @raymondfeng
in strongloop/loopback-context PR #1 comment #235931961
2016-07-29 17:49:32 +02:00
browser Rename to loopback-context/LoopBackContext 2016-07-29 09:36:34 +02:00
server Use cls-hooked instead of continuation-local-storage, 2016-07-29 17:49:32 +02:00
test Rename to loopback-context/LoopBackContext 2016-07-29 09:36:34 +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 Use cls-hooked instead of continuation-local-storage, 2016-07-29 17:49:32 +02:00
package.json Use cls-hooked instead of continuation-local-storage, 2016-07-29 17:49:32 +02:00

README.md

loopback-context

Current context for LoopBack applications, based on cls-hooked.

Usage

  1. Add per-request-context middleware to your server/middleware-config.json:
{
  "initial": {
    "loopback-context#per-request-context": {
    }
  }
}
  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 also https://docs.strongloop.com/display/APIC/Using+current+context