Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

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.
  • Loading branch information...
commit 91997e9c53db057667981d5f5ece6eb15a8d1059 1 parent 1393187
TJ Holowaychuk tj authored
Showing with 23 additions and 1 deletion.
  1. +1 −1  lib/router/index.js
  2. +22 −0 test/router.test.js
2  lib/router/index.js
View
@@ -193,7 +193,7 @@ Router.prototype._dispatch = function(req, res, next){
}
// match route
- route = self._match(req, i);
+ req.route = route = self._match(req, i);
// implied OPTIONS
if (!route && 'OPTIONS' == req.method) return self._options(req, res);
22 test/router.test.js
View
@@ -359,5 +359,27 @@ module.exports = {
assert.response(app,
{ url: '/foo', method: 'OPTIONS' },
{ body: 'whatever', headers: { Allow: 'GET' }});
+ },
+
+ 'test req.route': function(){
+ var app = express.createServer();
+
+ var routes = [];
+
+ app.get('/:foo?', function(req, res, next){
+ routes.push(req.route.path);
+ next();
+ });
+
+ app.get('/foo', function(req, res, next){
+ routes.push(req.route.path);
+ next();
+ });
+
+ assert.response(app,
+ { url: '/foo' },
+ function(){
+ routes.should.eql(['/:foo?', '/foo']);
+ });
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.