Skip to content
Myr

Fix router.use to accept array of middleware without path

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 bf1980f · Browse files · 3 files+35 added−2 removed
This commit

State

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

Diff stats

3 files+35 added−2 removed

  • tests:+22 added−0 removed
  • other:+13 added−2 removed

3 files+35 added−2 removed

modified:lib/router/index.js+12 added-2 removed
410 unmodified lines
411 var path = '/';412 var self = this;413414 // default path to '/'415 // disambiguate router.use([fn])416 if (typeof fn !== 'function') {417 var arg = fn;418419 while (Array.isArray(arg) && arg.length !== 0) {420 arg = arg[0];421 }422423 // first arg is the path424 if (typeof arg !== 'function') {416 offset = 1;417 path = fn;425 offset = 1;426 path = fn;427 }428 }429430 var callbacks = utils.flatten(slice.call(arguments, offset));431
145 unmodified lines
modified:test/Router.js+22 added
308 unmodified lines
309 router.use.bind(router, '/', 5).should.throw(/requires middleware function.*number/)310 router.use.bind(router, '/', null).should.throw(/requires middleware function.*Null/)311 router.use.bind(router, '/', new Date()).should.throw(/requires middleware function.*Date/)312 })313314 it('should accept array of middleware', function(done){315 var count = 0;316 var router = new Router();317318 function fn1(req, res, next){319 assert.equal(++count, 1);320 next();321 }322323 function fn2(req, res, next){324 assert.equal(++count, 2);325 next();326 }327328 router.use([fn1, fn2], function(req, res){329 assert.equal(++count, 3);330 done();331 });332333 router.handle({ url: '/foo', method: 'GET' }, {}, function(){});334 })335 })336337 describe('.param', function() {338 it('should call param function when routing VERBS', function(done) {
125 unmodified lines
modified:History.md+1 added
1unreleased2==========34 * Fix regression for empty string `path` in `app.use`5 * Fix `router.use` to accept array of middleware without path6 * Improve error message for bad `app.use` arguments784.9.1 / 2014-09-169==================
2251 unmodified lines