Skip to content
Myr

Implemented route middleware with arrays

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent c746025 · Browse files · 2 files+22 added−10 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+22 added−10 removed

  • tests:+15 added−9 removed
  • other:+7 added−1 removed

2 files+22 added−10 removed

modified:lib/express/server.js+7 added-1 removed
313 unmodified lines
314315 // Route specific middleware support316 if (arguments.length > 2) {317 for (var i = 1, len = arguments.length - 1; i < len; ++i) {318 if (Array.isArray(arguments[i])) {319 for (var j = 0, jlen = arguments[i].length; j < jlen; ++j) {320 this[method](path, arguments[i][j]);321 }322 } else {318 this[method](path, arguments[i]);323 this[method](path, arguments[i]);324 }325 }326 fn = arguments[arguments.length - 1];327 }328
6 unmodified lines
modified:test/express.test.js+15 added-9 removed
349 unmodified lines
350351 app.get('/xxx', allow('member'), restrictAge(18), function(req, res){352 res.send(200);353 });354355 app.get('/booze', [allow('member')], restrictAge(18), function(req, res){356 res.send(200);357 });358 359 ['xxx', 'booze'].forEach(function(thing){355 assert.response(app,356 { url: '/xxx' },357 { body: 'Unauthorized', status: 401 });358 assert.response(app,359 { url: '/xxx', headers: { 'X-Role': 'member' }},360 { body: 'Forbidden', status: 403 });361 assert.response(app,362 { url: '/xxx', headers: { 'X-Role': 'member', 'X-Age': 18 }},363 { body: 'OK', status: 200 });360 assert.response(app,361 { url: '/' + thing },362 { body: 'Unauthorized', status: 401 });363 assert.response(app,364 { url: '/' + thing, headers: { 'X-Role': 'member' }},365 { body: 'Forbidden', status: 403 });366 assert.response(app,367 { url: '/' + thing, headers: { 'X-Role': 'member', 'X-Age': 18 }},368 { body: 'OK', status: 200 });369 });370 }371};