-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Fastify 5.8.2 and autohooks produces "route already declared" error #376
Comments
@climba03003 wdyt? This might have been broken by #375? |
I am more incline to believe it broken by #368 Lines 87 to 89 in 64e6bf2
The problem exist when you provide a |
After double check the document, I can see it as intended behavior. Providing same |
So adding the prefix will just add the '/backend' to every route right? But the directory would still be appended to the prefix, so in the example:
Where is the "duplicate route" error coming from then? Or other way to ask: what would I have to configure so that every route will have a fixed prefix? I guess I could just get rid of the |
No, from the document is that all routes will use the This happen only when you don't use When you are providing |
I think we should decide which behavior is the correct one. But you can see it is very weird in the test below. It ignore the folder fastify-autoload/test/issues/326/autohooks/index.js Lines 13 to 18 in c1685f4
fastify-autoload/test/issues/326/test.js Lines 64 to 79 in c1685f4
cc @fastify/core |
@climba03003 can you summarize what question you are asking core? |
The current I prefer the latter. |
I really don't have an opinion. I have not used this module. |
The latter is how it is working in 5.8.0 and before, and I think it makes more sense, too. I use the prefix to have a prefix for all routes e.g. when sharing a hostname with other services and routing is then done by URL prefix. |
For me, just removing the autohooks.js fixed my problem. I can live with the missing encapsulation for now. Feel free to close. |
I've hit this problem too, it broke my system when moving from I'm using it in what seemed like a logical manner to me: fastify.register(AutoLoad, {
dir: 'routes/api',
options: { prefix: '/api' },
autoHooks: true,
cascadeHooks: true
}); and then a
I would expect the following routes to exist:
If this will not be the case going forward, how do I achieve this goal in the newer versions? |
Prerequisites
Fastify version
4.27.0
Plugin version
5.8.2
Node.js version
20.13.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.5
Description
When going from 5.8.0 to 5.8.2 my code base will throw a
FastifyError [Error]: Method 'GET' already declared for route '/backend'
error about having a duplicate route. I managed to reproduce this and added a simple repository to show the error.Link to code that reproduces the bug
https://github.com/mccare/fastify-autoload-hook
Expected Behavior
It should just register the route into /backend/example (in this case) and not try to register under /backend
The text was updated successfully, but these errors were encountered: