Skip to content
Myr

Fixed middleware/router precedence issue. Closes #366

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

You can now "use" your router in configure() blocks where ever you wish, ex: app.use(connect.bodyDecoder()) app.use(app.router) app.use(connect.staticProvider())

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 7b3eb23 · Browse files · 2 files+29 added−25 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+29 added−25 removed

  • tests:+24 added−23 removed
  • other:+5 added−2 removed

2 files+29 added−25 removed

modified:lib/express/server.js+5 added-2 removed
53 unmodified lines
54 next();55 });5657 // Use router, expose as app.get(), etc58 this.router = router(function(app){ self.routes = app; });58 var fn = router(function(app){ self.routes = app; });59 this.__defineGetter__('router', function(){60 this.__usedRouter = true;61 return fn;62 });63};6465/**66 * Inherit from `connect.Server`.
146 unmodified lines
213(function(method){214 Server.prototype[method] = function(path, fn){215 if (!this.__usedRouter) {216 this.use(this.router);213 this.__usedRouter = true;217 }218 this.routes[method](path, fn);219 return this;220 };
2 unmodified lines
modified:test/express.test.js+24 added-23 removed
196 unmodified lines
197 { url: '/', method: 'POST', data: 'name=tj', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},198 { body: 'tj' });199 },200201 // 'test #configure() precedence': function(assert){202 // var app = express.createServer();203 // 204 // app.configure(function(){205 // app.use(function(req, res, next){206 // res.writeHead(200, {});207 // res.write('first');208 // next();209 // });210 // app.use(app.router);211 // app.use(function(req, res, next){212 // res.end('last');213 // });214 // });215 // 216 // app.get('/', function(req, res){217 // res.write(' route ')218 // });219 // 220 // assert.response(app,221 // { url: '/' },222 // { body: 'first route last' });223 // },201 'test #configure() precedence': function(assert){202 var app = express.createServer();203 204 app.configure(function(){205 app.use(function(req, res, next){206 res.writeHead(200, {});207 res.write('first');208 next();209 });210 app.use(app.router);211 app.use(function(req, res, next){212 res.end('last');213 });214 });215 216 app.get('/', function(req, res, params, next){217 res.write(' route ');218 next();219 });220 221 assert.response(app,222 { url: '/' },223 { body: 'first route last' });224 },225 226 'test #set()': function(assert){227 var app = express.createServer();228 var ret = app.set('title', 'My App').set('something', 'else');229 assert.equal(app, ret, 'Test #set() returns server for chaining');
73 unmodified lines