Skip to content
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

Provide access to original unparsed path #85

Open
GuskiS opened this issue Nov 4, 2019 · 5 comments
Open

Provide access to original unparsed path #85

GuskiS opened this issue Nov 4, 2019 · 5 comments

Comments

@GuskiS
Copy link

GuskiS commented Nov 4, 2019

As discussed in expressjs/express#4084 there is a need for original path on req object.

Example:

router.get("/user/:id", (req, res, next) => {
  console.log(req.originalUnparsedPath);  // => "/user/:id"
  next();
});

originalUnparsedPath is just an example, but the name would be something along the lines.

@dougwilson
Copy link
Contributor

Hi! Thanks for the feature request. Can you provide more information around what you expect to use this for? For example, if the route is defined as

router.get(["/user/:id", "/person/:id"], (req, res, next) => {
  console.log(req.originalUnparsedPath);  // => "/user/:id"
  next();
});

would the expectation here be (a) you get that original array back (b) you get just the element in the array that matched the request url or (c) something else?

The feature request to too vague on what the goal is for the usage of this data is to gauge, if you can expand on what specific you're going to use it for as well. For example, what should it provide when there are routers mounted in routers?

@GuskiS
Copy link
Author

GuskiS commented Nov 4, 2019

Thanks for reply.
I wasn't aware you can use router API like that. That being said, I would expect req.originalUnparsedPath to work same way as req.originalUrl do, but just return the unparsed value.

router.get(["/user/:id", "/person/:id"], (req, res, next) => {
  console.log({ original: req.originalUrl, unparsed: req.originalUnparsedPath });
  next();
});
// => { original: "/user/123", unparsed: "/user/:id" }
// or
// => { original: "/person/123", unparsed: "/person/:id" }
// depending on request you make

I need to log it out and then create AWS metrics.

@wesleytodd
Copy link
Member

Does this PR satisfy this? #34

@GuskiS
Copy link
Author

GuskiS commented Nov 4, 2019

I suppose that would work, yes.

gabegorelick pushed a commit to gabegorelick/router that referenced this issue Jan 5, 2020
gabegorelick pushed a commit to gabegorelick/router that referenced this issue Jan 5, 2020
gabegorelick pushed a commit to gabegorelick/router that referenced this issue Jan 6, 2020
@donoftime2018
Copy link

donoftime2018 commented Nov 6, 2023

I cannot access originalUnparsedPath. I have express 4.18.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants