rgrove / combohandler

A simple Yahoo!-style combo handler in Node.js.
MIT License
116 stars 32 forks source link

This can no longer be used as middleware via `app.use()` #23

Open ericf opened 11 years ago

ericf commented 11 years ago

Express middleware used via app.use() requires a function, this commit https://github.com/rgrove/combohandler/commit/bc842d9ec1370dcd54d734b90ea7b97dc3140ce7 made combo.combine() always return an array.

ericf commented 11 years ago

Also, I'm unsure that even the implementation in <= 0.2.1 would even work in Express 3.x since the handler function always calls next() which will lead to a 404 since res.send() was never called.

evocateur commented 11 years ago

Oh, dang. Guess we should have a test for that case.

I'll have to do some digging to figure out when we know we're being used directly, vs in a route callback chain...

ericf commented 11 years ago

I think it's fine to add a new function to serve this feature which basically would have to manually call into the other middleware functions and can't rely on next().

evocateur commented 11 years ago

Yeah, I have an angle on inspecting the req.route.callbacks array, see if the current middleware is the end of the chain, and then just res.send(res.body) instead of next(). I fiddled with it a couple weeks ago (hence naming some of the anonymous functions returned as middleware), it's crazy what Express gives access to in the req and res objects.