router icon indicating copy to clipboard operation
router copied to clipboard

Make req.route an object saving route and baseUrl

Open tunniclm opened this issue 9 years ago • 3 comments

This PR attempts to implement https://github.com/expressjs/express/issues/2883.


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.

tunniclm avatar Feb 24 '16 14:02 tunniclm

Some thoughts/questions:

  • Is using __proto__ ok? It could instead copy the values to a new object {}, or alternatively should it be a new object with a differnet name, such as req.routeInfo, that contains properties req.routeInfo.route and req.routeInfo.baseUrl?
  • Is the test okay? Should it instead (or additonally) test the value of req.route.baseUrl in an error handler? Should it use a different style of test where the value checked is in the body of the response rather than a header?

tunniclm avatar Feb 24 '16 14:02 tunniclm

Any thoughts/feedback on this?

tunniclm avatar Mar 08 '16 16:03 tunniclm

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 2.0 branch? If you are interested in landing this for our push toward express@5 I would love to chat. If not, I think it will need to wait for v6. Let me know asap so I can work it into the plans.

wesleytodd avatar Mar 16 '24 18:03 wesleytodd