visionmedia/express — pull request #1511 by jonathanong (2013-02-18 22:48:22+00:00)
Title: [WIP] Add app.subroute option for method chaining middleware for routes, as well as automatic OPTIONS responses and 405 Method Not Allowed error codes

app.subroute('/foo')
.get(getMiddleware)
.post(postMiddleware)
.end()

Will be equivalent to:

app.get('/foo', getMiddleware)
app.post('/foo', postMiddleware)
app.options('/foo', function(req, res, next){
res.setHeader('Allow', 'GET,HEAD,POST,OPTIONS')
res.end()
})
app.all('/foo', function(req, res, next){
var err = new Error()
err.status = 405
next(err)
})

This kind of implements @guille's #1501 alternative route syntax.
This also alleviates #1499 405 Method Not Allowed routing.

There are, however, issues with this code. If you're interested in merging this, I can work on it more, otherwise I'm not.

- `app.subroute().all` will add all of `require('methods')` methods to the `Allow` options header. This isn't ideal since most people are only going to use a small subset of those methods, but technically that's what `app.all` does.
- I was under the impression that `app.get` accepted `HEAD` requests but doesn't send a body as per HTTP spec, but I guess that isn't the case. Not sure how to handle it.
- All routes have to be declared in the same `app.subroute()` for `OPTIONS` to work.
Let me know what you think.