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

Route paths must be sorted after definition and before adding them to express. #35

Open
guimello opened this issue May 8, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@guimello
Copy link

guimello commented May 8, 2020

Problem

Routes must follow a precedence definition when adding them to express.

app.get('things/:id', func);
app.get('things/dance', func);

The second api will never match because the dynamic id key will match dance. So in order to solve this, the routes must be defined as such:

app.get('things/dance', func);
app.get('things/:id', func);

Proposal

Maybe we should automatically sort the routes by their path definition, giving precedence to not dynamic path keys.

Pros
  • avoid user mistake when defining routes
Cons
  • doing this automatically could be an issue if later on the road we allowed Route#path to be a function instead of string.
@fsmaia
Copy link
Collaborator

fsmaia commented May 8, 2020

Amazing idea 🚀
I think we could create our own Request and Response interfaces too (even if they just extend express), so users wouldn't be aware of express complexity and interfaces :)

@rhberro rhberro added the enhancement New feature or request label May 13, 2020
nolleto added a commit to nolleto/the-fake-backend that referenced this issue May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants