Skip to content

Provide access to original unparsed path #85

Open

Description

@GuskiS

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.

Activity

  1. dougwilson commented on Nov 4, 2019

    @dougwilson
    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?

  2. GuskiS commented on Nov 4, 2019

    @GuskiS
    Author

    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.

  3. wesleytodd commented on Nov 4, 2019

    @wesleytodd
    Member

    Does this PR satisfy this? #34

  4. GuskiS commented on Nov 4, 2019

    @GuskiS
    Author

    I suppose that would work, yes.

  5. added 3 commits that reference this issue on Jan 5, 2020
    f2f59a3
    a0afed7
    05babdf
  6. donoftime2018 commented on Nov 6, 2023

    @donoftime2018

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions