How can I create Express/Connect middleware which wrap each request in its own domain?
I've had good luck replacing the stock
var app = express.createServer();
with:
var domainCreate = require('domain').create;
var app = express.createServer(function (req, res, next) {
var domain = domainCreate();
domain.run(next);
});
Then in your middleware you can add properties to process.domain or add additional error handling.