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

fix: dynamic routes override non dynamic ones. #658

Closed
erickzanardo opened this issue May 23, 2023 · 1 comment · Fixed by #687
Closed

fix: dynamic routes override non dynamic ones. #658

erickzanardo opened this issue May 23, 2023 · 1 comment · Fixed by #687
Labels
bug Something isn't working as expected

Comments

@erickzanardo
Copy link
Contributor

Description

When declaring a dynamic route, they will always take precedence over a non dynamic on. For example, imagine that I have the following route:

GET /turtles/[id]

And the following:

POST /turtles/random

When calling curl -X POST http://localhost:8080/turtles/random, routes/turtles/[id]/index.dart will be called instead of routes/turtles/random.dart, which can be confusing.

Steps To Reproduce

  1. clone https://github.com/erickzanardo/ninja_turtles_api
  2. start the server
  3. curl -X POST http://localhost:8080/turtles/random
  4. See the 405 error

Expected Behavior

I understand that this can be considered an expected behaviour, one could argue that random is simply an id that the index.dart inside the /turtles/[id]/folder should consider and handle. Which I completely agree, but on the other hand,random.dartand[id]/index.dart` files are conflicting routes.

I believe there are two possible ways of fixing this:

  • Non dynamic routes should take precedence over dynamic ones, so we could check for non dynamic route handlers before checking in dynamics ones, that way the example above would work. I believe this to be a preferred way of handling this, being able to split handlers like this can lead to a more organized route structure where we would be able to better split similar routes in different files.
  • Identify these conflicts and give a warning to the user
@erickzanardo erickzanardo added the bug Something isn't working as expected label May 23, 2023
@alestiago
Copy link
Contributor

Linking a similar issue #631 for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
2 participants