Question: Can I add a root path to the app
See original GitHub issueIs your feature request related to a problem? Please describe.
I currently have all my endpoints as /products
, /products/:id
etc.
I would like to add a root path to all of these endpoints such as /api/v1
so every endpoint gets that path prepended to them - api/v1/products
, api/v1/products/:id
etc.
To give an idea, you could do within basic express app using:
app.use('/api/v1', allRoutes);
Describe the solution you’d like
I would prefer a configuration parameter such as rootPath
which then behaves as mentioned above. Alternatively, I wouldnt mind if there is a document on how to add plugins/middlewares to make this happen.
Describe alternatives you’ve considered
Alternatively, you could just add the /api/v1
on every single routes but thats not an ideal solution because if I have something around 30+ endpoints, its tedious.
Additional context No additional context
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
If I am being honest, I am not really convinced with this solution. While it does work, I think it would be counterproductive having an additional config just to add a root path. The same can be achieved by creating an appropriate folder structure.
I do like the idea of being able to inject some middlewares as proposed in the issue earlier, since that approach could have utilities not limited to only adding a root path.
Proposal We introduce a file called
middleware.js
, which contains an IIFE declaring/configuring required middlewares. At startup, Camouflage checks if the filemiddleware.js
exists at the root of the project. (and if injection is enabled). If both conditions are fulfilled, the middleware IIFE is executed.Example
middleware.js
There would require a significant refactoring to expose
allRoutes
, but if we were to implement this, middleware injection would be a more elegant solution in my opinion.Closed in #185