Skip to content

Commit

Permalink
Register multiple routes with array of paths.
Browse files Browse the repository at this point in the history
Closes #203.
  • Loading branch information
alexmingoia committed Nov 25, 2015
1 parent 8665620 commit dde14ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,18 @@ Router.prototype.redirect = function (source, destination, code) {
Router.prototype.register = function (path, methods, middleware, opts) {
opts = opts || {};

var router = this;
var stack = this.stack;

// support array of paths
if (Array.isArray(path)) {
path.forEach(function (p) {
router.register.call(router, p, methods, middleware, opts);
});

return this;
}

// create route
var route = new Layer(path, methods, middleware, {
end: opts.end === false ? opts.end : true,
Expand Down
10 changes: 10 additions & 0 deletions test/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,16 @@ describe('Router', function () {
router[method]('/', function () {}).should.equal(router);
});
});

it('registers array of paths (gh-203)', function () {
var router = new Router();
router.get(['/one', '/two'], function (ctx, next) {
return next();
});
expect(router.stack).to.have.property('length', 2);
expect(router.stack[0]).to.have.property('path', '/one');
expect(router.stack[1]).to.have.property('path', '/two');
});
});

describe('Router#use()', function (done) {
Expand Down

0 comments on commit dde14ae

Please sign in to comment.