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.

Global subdomain OR prefix

See original GitHub issue

Feature Request

Is your feature request related to a problem? Please describe.

If I have an api with an endpoint of mydomain.tld/api I also want to be able to access it via api.mydomain.tld. In an express app it is easy enough to use the express-subdomain package and include the routes like

routes = express.Router();

routes.use('endpoint', doStuff);

app.use(subdomain('api', routes));
app.use('/api', routes);

But I don’t see anywhere in the docs that I could extend the controller registration process to include my own logic.

Describe the solution you’d like

Some method to extend the controller registration process, to register additional handlers.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, Jun 29, 2021

I want to be able to have all routes on either, but not both.

Wouldn’t it be easier to set up a reverse proxy (nginx?) in front of your API which redirects api. to /api or the other way round?

To answer your question, currently, you can only register a subdomain per-controller (https://docs.nestjs.com/controllers#sub-domain-routing) and the globally registered prefix would apply here as well (unless you explicitly exclude each endpoint that is supposed to be accessible from the subdomain). In v8 (which is supposed to be released in a few days), you should be able to use RouterModule to register a prefix per module instead of globally for each route. With that, you could technically split each module into 2 modules in which one registers endpoints without the subdomain (but with the api prefix), and another one these endpoints that need /api.

Still, even though it’s technically doable (definitely easier with v8), I’d rather recommend using a proxy in front.

For further questions, please, use our Discord channel (support).

0reactions
dariusj18commented, Jun 29, 2021

Legacy migration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global prefix - FAQ | NestJS - A progressive Node.js framework
Global prefix. To set a prefix for every route registered in an HTTP application, use the setGlobalPrefix() method of the INestApplication instance.
Read more >
global-prefix - npm
global-modules: The directory used by npm for globally installed npm modules. | homepage · global-paths: Returns an array of unique "global" ...
Read more >
Global Prefix Routing | RingCentral Contact Center
This article provides information about Global Prefix Routing in the RingCentral Contact Center platform.
Read more >
Subdomains vs ccTLDs: Which domain strategy is best for ...
The right website domain name structure will help you target international users and appear higher up on regional search engine results.
Read more >
List of international call prefixes - Wikipedia
Countries by international prefixEdit · Africa: all countries except Kenya, Nigeria, Tanzania and Uganda · Asia: all countries except several countries in Central ......
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