-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose matched route #223
Comments
I'd also like to know what route was matched (separate from the URL on the request) so I could access it in a middleware for monitoring. Say I have some route like this: route.get('/foo/:id/:type', function*() { this.body = "ok" }) I'd like to be able to create a middleware like this: function* routeMetrics(next) {
var start = Date.now()
yield next
var duration = Date.now() - start
// send a metric
statsd.timing(this.matchedRoute, duration)
// this.matchedRoute would be the string of the matched route, so '/foo/:id/:type/' in this case
}
route.get('/foo/:id/:type', routeMetrics, function*() { this.body = "ok" }) |
if you add another similar but more generic route, this._matchedRoute always gives the more generic route instead of the actually matched more specific one router.get('/users/:id', function *() {
// this._matchedRoute is '/:username/:id'
});
router.get('/:username/:id', function *() {
// this._matchedRoute is '/:username/:id'
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to know in the common middlewares for all routes which route will finally be served. Couldn't find a way to do this.
The text was updated successfully, but these errors were encountered: