Skip to content
Myr

Invoke router.param() only when route matches

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

fixes #2206

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent efbc3f9 · Browse files · 4 files+56 added−3 removed
This commit

State

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

Diff stats

4 files+56 added−3 removed

  • tests:+25 added−0 removed
  • other:+31 added−3 removed

4 files+56 added−3 removed

modified:lib/router/index.js+11 added-3 removed
189 unmodified lines
190 if (err) {191 return next(err);192 }193194 req.route = route;194 var has_method = route._handles_method(method);195196 // we can now dispatch to the route197 if (method === 'options' && !route.methods['options']) {196 // build up automatic options response197 if (!has_method && method === 'options') {198 options.push.apply(options, route._options());199 }200201 // don't even bother202 if (!has_method && method !== 'head') {203 return next();204 }205206 // we can now dispatch to the route207 req.route = route;208 }209210 // Capture one-time layer values211 req.params = self.mergeParams
308 unmodified lines
modified:lib/router/route.js+19 added
modified:test/app.param.js+25 added
175 unmodified lines
176 .get('/bob')177 .expect('loki', done);178 })179180 it('should not invoke without route handler', function(done) {181 var app = express();182183 app.param('thing', function(req, res, next, thing) {184 req.thing = thing;185 next();186 });187188 app.param('user', function(req, res, next, user) {189 next(new Error('invalid invokation'));190 });191192 app.post('/:user', function(req, res, next) {193 res.send(req.params.user);194 });195196 app.get('/:thing', function(req, res, next) {197 res.send(req.thing);198 });199200 request(app)201 .get('/bob')202 .expect(200, 'bob', done);203 })204205 it('should work with encoded values', function(done){206 var app = express();207208 app.param('name', function(req, res, next, name){
78 unmodified lines
modified:History.md+1 added
9 unmodified lines
10 - merges `req.params` from parent routes11 * deprecate things with `depd` module12 * fix behavior when handling request without routes13 * fix handling when `route.all` is only route14 * invoke `router.param()` only when route matches15 * restore `req.params` after invoking router16 * use `finalhandler` for final response handling17 * use `media-typer` to alter content-type charset18 * deps: accepts@~1.0.7
1722 unmodified lines