-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Make req.route an object saving route and baseUrl #37
base: master
Are you sure you want to change the base?
Conversation
When using an error handler you have access to req.route which describes the most recently matched route. However, some other informaiton (like req.baseUrl) gets changed before the error handler runs. This commit changes req.route to an object that also contains the req.baseUrl before it gets changed. Since the actual route object is not scoped to the current event, this commit instead uses a new object to store the baseUrl but sets the __proto__ to the route object so that all its properties are also available.
Some thoughts/questions:
|
@@ -271,7 +271,8 @@ Router.prototype.handle = function handle(req, res, callback) { | |||
|
|||
// store route for dispatch on change | |||
if (route) { | |||
req.route = route | |||
req.route = req.route || { __proto__: route } | |||
req.route.baseUrl = req.baseUrl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, must remove the habitual ;
Any thoughts/feedback on this? |
7e90c9e
to
8643ec6
Compare
Hey! I am (finally) getting around to trying to wrangle these and I think that this is a good idea. Sadly I think it is breaking and since it is so old I am not sure it is a good idea to revive this as is or take a new try specifically on top of the |
This PR attempts to implement expressjs/express#2883.
When using an error handler you have access to
req.route
which describes the most recently matched route. However, some other informaiton (likereq.baseUrl
) gets changed before the error handler runs.This commit changes
req.route
to an object that also contains thereq.baseUrl
before it gets changed.Since the actual
route
object is not scoped to the current event, this commit instead uses a new object to store thebaseUrl
but sets the__proto__
to theroute
object so that all its properties are also available.