Skip to content
Myr

Add app.router reference back

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 78e5054 · Browse files · 2 files+32 added−46 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+32 added−46 removed

  • other:+32 added−46 removed

2 files+32 added−46 removed

modified:lib/application.js+30 added-46 removed
32 unmodified lines
33 * @api private34 */3536app.init = function(){37 var router = null;3839 this.cache = {};40 this.settings = {};41 this.engines = {};42 this.defaultConfiguration();4344 // Setup getting to lazily add base router45 Object.defineProperty(this, 'router', {46 configurable: true,47 enumerable: true,48 get: function getrouter() {49 if (router === null) {50 router = new Router({51 caseSensitive: this.enabled('case sensitive routing'),52 strict: this.enabled('strict routing')53 });54 }5556 return router;57 }58 });59};6061/**62 * Initialize application configuration.
40 unmodified lines
103 }104};105106/**89 * lazily adds the base router if it has not yet been added.90 *91 * We cannot add the base router in the defaultConfiguration because92 * it reads app settings which might be set after that has run.93 *94 * @api private95 */96app.lazyrouter = function() {97 if (!this._router) {98 this._router = new Router({99 caseSensitive: this.enabled('case sensitive routing'),100 strict: this.enabled('strict routing')101 });102 }103};104105/**107 * Dispatch a req, res pair into the application. Starts pipeline processing.108 *109 * If no _done_ callback is provided, then default error handlers will respond110 * in the event of an error bubbling through the stack.
1 unmodified line
112 * @api private113 */114115app.handle = function(req, res, done) {115 var router = this._router;116116 // final handler117 done = done || finalhandler(req, res, {118 env: this.get('env'),119 onerror: logerror.bind(this)120 });121123 // no routes124 if (!router) {125 debug('no routes defined on app');126 done();127 return;128 }129122 // set powered by header123 if (this.enabled('x-powered-by')) {124 res.setHeader('X-Powered-By', 'Express');125 }
10 unmodified lines
136 if (!res.locals) {137 res.locals = Object.create(null);138 }139148 router.handle(req, res, done);140 this.router.handle(req, res, done);141};142143/**144 * Proxy `Router#use()` to add middleware to the app router.
30 unmodified lines
175 if (fns.length === 0) {176 throw new TypeError('app.use() requires middleware functions');177 }178187 // setup router188 this.lazyrouter();189 var router = this._router;179 // get router180 var router = this.router;181182 fns.forEach(function (fn) {183 // non-express app184 if (!fn || !fn.handle || !fn.set) {
30 unmodified lines
215 *216 * @api public217 */218228app.route = function(path){229 this.lazyrouter();230 return this._router.route(path);219app.route = function route(path) {220 return this.router.route(path);221};222223/**224 * Register the given template engine callback `fn`
47 unmodified lines
272 * @return {app} for chaining273 * @api public274 */275286app.param = function(name, fn){287 this.lazyrouter();288276app.param = function param(name, fn) {277 if (Array.isArray(name)) {290 name.forEach(function(key) {291 this.param(key, fn);292 }, this);278 for (var i = 0; i < name.length; i++) {279 this.param(name[i], fn);280 }281 return this;282 }283296 this._router.param(name, fn);284 this.router.param(name, fn);285 return this;286};287288/**
128 unmodified lines
417methods.forEach(function(method){418 app[method] = function(path){419 if ('get' == method && 1 == arguments.length) return this.set(path);420433 this.lazyrouter();434435 var route = this._router.route(path);421 var route = this.route(path);422 route[method].apply(route, slice.call(arguments, 1));423 return this;424 };425});
8 unmodified lines
434 * @api public435 */436437app.all = function(path){452 this.lazyrouter();453454 var route = this._router.route(path);438 var route = this.route(path);439 var args = slice.call(arguments, 1);440 methods.forEach(function(method){441 route[method].apply(route, args);442 });
120 unmodified lines
modified:History.md+2 added
7 unmodified lines
8 - `express.query` middleware9 * change:10 - `req.host` now returns host (`hostname:port`) - use `req.hostname` for only hostname11 - `req.query` is now a getter instead of a plain property12 * add:13 - `app.router` is a reference to the base router14154.10.1 / 2014-10-2816===================17
2447 unmodified lines