Commit Graph

1 Commits

Author SHA1 Message Date
Miroslav Bajtoš b38f2dc2d9 Middleware phases - initial implementation
Modify the app and router implementation, so that the middleware is
executed in order defined by phases.

Predefined phases: 'init', 'routes', 'files', 'final'

Methods defined via `app.use`, `app.route` and friends are executed
as the first thing in 'routes' phase.

API usage:

    // get a Phase object
    app.phase('init');

    // register middleware handlers in a phase
    app.phase('init').before(handler);
    app.phase('init').use(handler);
    app.phase('init').after(errorHandler);

    // regular handler
    function handler(req, res, next) {
      // do stuff
      next();
    }

    // error handler
    function errorHandler(err, req, res, next) {
      // handle error and/or call next
      next(err);
    }
2014-11-07 11:29:03 +01:00