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

Unable to override dynamic param route #2694

Open
yassilah opened this issue Aug 27, 2024 · 1 comment
Open

Unable to override dynamic param route #2694

yassilah opened this issue Aug 27, 2024 · 1 comment

Comments

@yassilah
Copy link
Contributor

Environment


  • Operating System: Linux
  • Node Version: v18.20.3
  • CLI Version: 3.13.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]

Reproduction

https://stackblitz.com/edit/github-xqvnbx?file=server%2Froutes%2Findex.ts

Describe the bug

What I am trying to achieve is the following:

  • have a default set of nested endpoints with dynamic parameters;
  • override specific paths to handle the request differently;
  • preserve untouched nested routes.

The use case is to create a simple CRUD API for each table of a database, e.g.:

  • GET /api/foo -> /api/[table]/index.get.ts
  • POST /api/foo -> /api/[table]/index.post.ts
  • GET /api/foo/1 -> /api/[table]/[id].get.ts
  • PATCH /api/foo/1 -> /api/[table]/[id].patch.ts
  • DELETE /api/foo/1 -> /api/[table]/[id].delete.ts

while preserving the ability to override a specific endpoint for a table that requires specific handling, e.g.:

  • GET /api/bar -> /api/bar/index.get.ts

In doing so, I would expect PATCH /api/bar/1 to still work but it seems that Nitro will discard any /api/bar/* endpoints after creating that file.

Additional context

No response

Logs

No response

@pi0
Copy link
Member

pi0 commented Aug 27, 2024

Hi. sadly this is a limitation of route matcher algorithm in nitro v2 (radix3). in nitro v3, we use new implementation (rou3) which should handle this well. i will try to test it in a local app but you can also directly test nitro v3 via nightly channel.

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

2 participants