plugins/setContext.js
function setContextPlugin(options) {
  var seneca = this;
  var plugin = 'set-context';

  options = seneca.util.deepextend({
    createContext: createContext,
    contextHeader: 'x-request-id'
  }, options);

  seneca.act({
    role: 'web',
    plugin: plugin,
    use: processRequest.bind(null, options)
  });

  return {name: plugin};
}
function setContextPlugin(options) {
  var seneca = this;
  var plugin = 'set-context';

  options = seneca.util.deepextend({
    createContext: createContext,
    contextHeader: 'x-request-id'
  }, options);

  seneca.act({
    role: 'web',
    plugin: plugin,
    use: processRequest.bind(null, options)
  });

  return {name: plugin};
}
function setContextPlugin ( options ) { var seneca = this ; var plugin = 'set-context' ; options = seneca . util . deepextend ( { createContext : createContext , contextHeader : 'x-request-id' } , options ) ; seneca . act ( { role : 'web' , plugin : plugin , use : processRequest . bind ( null , options ) } ) ; return { name : plugin } ; }
A seneca plugin, which automatically sets the context for all HTTP requests.

@param {{
// A function which creates a context based on the HTTP request and response.
// It is used by the `setContextPlugin`.
// The `defaultContext` is `{requestId: req.headers[options.contextHeader]}`.
// Default is noop.
createContext: function (request, response, defaultContext, function(error, context))

// The name of the HTTP request header containing the request context.
// Default is 'x-request-id'.
contextHeader: string
}} options
A seneca plugin which automatically sets the context for all HTTP requests .