mikeal/tako — pull request #15 by isaacs (2012-04-24 00:27:09+00:00)
Title: Plugins

This is a bunch of the Route/plugins refactoring that we were talking about. It's not ready for prime-time, but I want to check-in at this point to make sure we're not diverging.

Caveats:

1. `route.must('thing', handler)` breaks the pattern of `route.accepts(..., handler)`. It makes it look like the handler you pass to must is what gets set if you DO have the thing, when in fact, it's what gets set if you *don't* have it. So you'd do something like `route.must('auth', 401)` to say "You must auth, or else you get a 401 error".

2. Something apparently is busted in filed when I try to use it for stuff, though all the tests pass. I'm seeing a lot of `'Not Implemented, lazy (future) dynamic read/write discovery,'` errors. Also, it seems to set the 200 status code, even when a file is being used as a 404 error, which is weird and wrong.

3. Error handling, omg, it's such a mess. There needs to be some consistent/intuitive way to say, "Yeah, I know what I told you before, but forget all that, this is an error now, deal with it", and then provide some handler to send the error contents. But, you probably want those error handlers to also do content type negotiation, so that means they really ought to be Routes rather than just handlers.

4. routes.Route vs Route vs route.Router vs Router. This is extremely confusing and weird. I cleaned it up a bit by making the result of router.match() go into req.match rather than req.route, so req.route is always and only a reference to the tako route. But it's still really just kind of screwy still. I get why there needs to be two kinds of Route objects (since routes.Route objects are just a dumb little regexp-and-function thingie), but why is there two different kinds of Routers?