Giter VIP home page Giter VIP logo

Comments (4)

blakeembrey avatar blakeembrey commented on July 24, 2024

@jisaacks This is intentional. strict is for matching (or not) the trailing slashes and has no affect on app.use. That uses the end: false feature, which is meant for matching path segments (not extensions). Enabling it for path segments and extensions would leave a confusing experience for users.

Maybe you could give some information on the use-case?

from path-to-regexp.

jisaacks avatar jisaacks commented on July 24, 2024

Ahh. Thanks for the quick reply. My use case is, I am writing a middleware to mount a restful json api. Currently you can mount it like so: app.use( "/some/path", json_api(db) ) and it gives you the following routes:

  • GET /some/path
  • POST /some/path
  • GET /some/path/:id
  • PUT /some/path/:id
  • DELETE /some/path/:id

I would like to make it also add the same routes with the .json extension. For routes like /some/path/23.json it is easy. I cannot get it to work with /some/path.json though because it does not match the regex generated for the middleware.

from path-to-regexp.

blakeembrey avatar blakeembrey commented on July 24, 2024

That makes sense. Unfortunately, adding a feature like that would break a lot of user assumptions. Could you imagine unknowingly having .json and /123 passed into your routes? It's unlikely the majority of people would handle this use-case and we could be breaking a lot of users code (or at least running a lot of unnecessary nested middleware).

As an aside, I'd look into using the function you already have and passing in the "prefix". E.g. json_api('/path', db). Then this can be used to return a router instance and all would work as expected.

Let me know if there's anything more I can do to help, but hopefully that makes sense! 😄

from path-to-regexp.

jisaacks avatar jisaacks commented on July 24, 2024

Yeah that makes a lot of sense, good idea. Thanks! :)

from path-to-regexp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.