Skip to content
Myr

Added `req.route`, exposing the current route. Closes #11

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

this can be used with a dynamicHelper to expose the _last_ route that was matched, aka the end-point when rendering a template. this is a `Route` instance, so it has .path, .regexp, etc.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 1393187 · Browse files · 2 files+23 added−1 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+23 added−1 removed

  • tests:+22 added−0 removed
  • other:+1 added−1 removed

2 files+23 added−1 removed

modified:lib/router/index.js+1 added-1 removed
191 unmodified lines
192 pass(req._route_index + 1);193 }194195 // match route196 route = self._match(req, i);196 req.route = route = self._match(req, i);197198 // implied OPTIONS199 if (!route && 'OPTIONS' == req.method) return self._options(req, res);200
183 unmodified lines
modified:test/router.test.js+22 added
357 unmodified lines
358359 assert.response(app,360 { url: '/foo', method: 'OPTIONS' },361 { body: 'whatever', headers: { Allow: 'GET' }});362 },363 364 'test req.route': function(){365 var app = express.createServer();366367 var routes = [];368369 app.get('/:foo?', function(req, res, next){370 routes.push(req.route.path);371 next();372 });373374 app.get('/foo', function(req, res, next){375 routes.push(req.route.path);376 next();377 });378379 assert.response(app,380 { url: '/foo' },381 function(){382 routes.should.eql(['/:foo?', '/foo']);383 });384 }385};