question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Can I add a root path to the app

See original GitHub issue

Is 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:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shubhendumadhukarcommented, Jul 18, 2022

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 file middleware.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

(()=>{
  const actuator = require('express-actuator');

  app.use(actuator());
  app.use('/api/v1', allRoutes);
});

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.

0reactions
shubhendumadhukarcommented, Aug 21, 2022

Closed in #185

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application root path - Stack Overflow
Has anyone got a reliable way to resolve root path for all above requirements? So - what should GetRootPath be doing? PS: I...
Read more >
how to give the approot path in launch.json file?
You can set the App Root in two places. First is as part of the VS Code preferences. Search for Mdk: Debug App...
Read more >
Azure App service not able to find root folder path "Could not ...
Hi,. I am facing one weird issue. I have created one web application that read the pdf file available in root location of...
Read more >
Find the Document Root of your Website - InMotion Hosting
In this article, we will explain the public_html folder, your website's document root, and add-on and subdomains doc root.
Read more >
Multi-root Workspaces in Visual Studio Code
Add a folder or multiple folders to the last active VS Code instance for a multi-root workspace. code --add vscode vscode-docs. Removing folders....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found