Advanced CLS (continuation local storage) middleware (for express, restify, ...)
var session = mwCLS.createNamespaceMiddleware('session');run the following middleware within the namespace
var mwCLS = require('mw-cls');
var session = mwCLS.createNamespaceMiddleware('session');
app.use(session.run());- set the namespace keypath with a value
- defaults: force = true
- force - force creates the keypathpath if it DNE
var mwCLS = require('mw-cls');
var session = mwCLS.createNamespaceMiddleware('session');
app.use(session.run()); // must be first
app.get('/',
session.set('foo.bar.baz', 'value'), ...);
// cls.getNamespace('session').get('foo').bar.baz becomes 'value'- set the namespace keypath as the result of an async function
- defaults: opts = { force: true, includeError: false }
- force - force creates the keypathpath if it DNE
- includeError - specify whether to ignore/include the error arg
var mwCLS = require('mw-cls');
var session = mwCLS.createNamespaceMiddleware('session');
function asyncValue (cb) {
setTimeout(function () {
cb(null, 'value');
}, 100);
}
app.use(session.run()); // must be first
app.get('/',
session.asyncSet('foo.bar.baz', asyncValue), ...);
// cls.getNamespace('session').get('foo').bar.baz becomes 'value'includeError option
var mwCLS = require('mw-cls');
var session = mwCLS.createNamespaceMiddleware('session');
function asyncValue (cb) {
setTimeout(function () {
cb(null, 'value');
}, 100);
}
app.use(session.run()); // must be first
var opts = { includeError:true };
app.get('/',
session.asyncSet('foo', asyncValue, opts), ...);
// cls.getNamespace('session').get('foo') becomes [null, 'value']- res.send the value for the namespace keypath
- defaults: code = 200
var mwCLS = require('mw-cls');
var session = mwCLS.createNamespaceMiddleware('session');
app.use(session.run()); // must be first
app.get('/',
session.set('foo.bar.baz', 'value'),
session.send('foo.bar.baz'));
// session.get('foo').bar.baz becomes 'value'
// res.sends 'value', code defaults to 200- res.json the value for the namespace key
- defaults: code = 200
var mwCLS = require('mw-cls');
var session = mwCLS.createNamespaceMiddleware('session');
app.use(session.run()); // must be first
app.get('/',
session.set('foo.bar.baz', 'value'),
session.json('foo.bar'));
// session.get('foo').bar.baz becomes 'value'
// res.sends { bar: 'value' }, code defaults to 200mv, cp, del, unset, setFromReq
MIT
