Skip to content

othiym23/cls-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connect / Restify middleware for CLS

Dirt-simple middleware for Connect and Restify handlers into a continuation-local storage context.

Example app.js:

var cls     = require('continuation-local-storage');
var express = require('express');
var clsify  = require('cls-middleware');
var route   = require('./route.js');

var ns = cls.createNamespace('namespace');

var app = express();
app.use(clsify(ns));

ns.set('whatever', 'a value');

app.get('/users', route);

with ./route.js:

var cls = require('continuation-local-storage');

module.exports = function (req, res, next) {
  // pulling from the namespace, and set up per request
  res.send({value : cls.getNameSpace('namespace').get('whatever')});

  next();
};

About

Connect & Restify middleware to bind routes to continuation-local storage

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •