Shouldn't next() run after d.enter()?
I haven't verified this, but it looks like the current design won't actually run Express middleware inside the domain, since you only call d.enter() after running next().
Also, I don't think app.use(dhs) will work at all, since connect will think it's an error handler. (since it has arity 4; see https://github.com/senchalabs/connect/blob/master/lib/proto.js#L189-L190)
Wow, I didn't realize that connect sniffs the arity of the function. That's kind of gross.
Yes; that's really annoying. I'd like to write a connect / express wrapper that allows middleware / route handlers to return promises, and the arity sniffing makes it more complicated.
IIRC, you can't even set .length by hand to fake it, since it's readonly. (I didn't try defineProperty())
just do this: https://github.com/brianc/node-domain-middleware/blob/master/index.js#L8