This refactor removes the assignment of routes based on file path and undocumented file export requirements. This has several advantages:
Available routes are defined in code not in file structure. This makes the paths explicitly declared instead of being built at run time. No more need for error handling cases where the file structure and content no longer matches the route import script.
Ensures all routes are given the BASE_ENDPOINT prefix. No chance for errors by a new route not including this in their path. Routers can still be added in the server.ts file if they should not use the BASE_ENDPOINT prefix.
Ensures no (unintentional) path collisions. The paths are all defined in the routes/index.ts file. This makes it easy to trace through the code to determine a route's path, and to see if you have any collisions since all the paths for a given router are handled in the same file.
In general I think this simplifies reading and maintaining the code by removing some of the magic that was happening.
This refactor removes the assignment of routes based on file path and undocumented file export requirements. This has several advantages:
BASE_ENDPOINT
prefix. No chance for errors by a new route not including this in their path. Routers can still be added in theserver.ts
file if they should not use theBASE_ENDPOINT
prefix.routes/index.ts
file. This makes it easy to trace through the code to determine a route's path, and to see if you have any collisions since all the paths for a given router are handled in the same file.In general I think this simplifies reading and maintaining the code by removing some of the magic that was happening.