fastify / fastify-autoload

Require all plugins in a directory
MIT License
333 stars 67 forks source link

Each folder needs to have a routes.ts/js file in order for deeper route.ts files to work if there is an autohooks.ts file #407

Closed AnzeKop closed 3 months ago

AnzeKop commented 3 months ago

Prerequisites

Fastify version

4.28.1

Plugin version

5.8.2

Node.js version

20

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Sonoma

Description

If you have a folder structure where you have a parent folder with just an autohooks.ts and then subfolders with routes.ts the routes in the child folders will not work unless you create an empty routes.ts file in the parent folder.

If you don't add an autohooks.ts file then it also works just fine but if you have a (protected) folder and just want to have an autohooks in there for validation the subsequent routes won't register unless you add an empty routes.ts file.

Link to code that reproduces the bug

No response

Expected Behavior

No response

jean-michelet commented 3 months ago

Thanks for reporting,

  1. Can you provide a repository that reproduces the bug as indicated, please? This helps us to investigate on a concrete basis.

  2. Do you know if this bug has been introduced recently? Does it work with previous patches and/or minors?

jean-michelet commented 3 months ago

@AnzeKop

Is this still an issue?

AnzeKop commented 3 months ago

@jean-michelet,

This has been fixed. It turned out that even if dirNameRoutePrefix was set to true when there we no autohooks.ts files it preffer the autoPrefix export but as soon as I gave it a an autohooks.ts it was going off dirNameRoutePrefix and changing all of my endpoints. I turned that to false and it then worked as expected.

I had autohooks and cascade hooks turned on in the config