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 route for all controllers

See original GitHub issue

Hi,

is there any suggested way how to set a “global” route for all controllers?

For example, I want to define this route: /api/

for my controllers:

@Controller('user')
export class UserController

@Controller('customer')
export class CustomerController

with the following result:

/api/user
/api/customer

Thank you

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

35reactions
kamilmysliwieccommented, May 23, 2017

Hi @jezikk, Since version 2.1.0 you can use setGlobalPrefix(prefix: string) method. Example:

const app = NestFactory.create(ApplicationModule);
app.setGlobalPrefix('api');
1reaction
kgajowycommented, Apr 10, 2019

@flogvit

// document
    .setBasePath('v1')

As you can create multiple swagger documents (like, for every API version) it makes sense that it is no automatically derived from app

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global route for all ApiControllers in .Net 6 - Stack Overflow
This work fine but i need to put this route top of all my ApiControllers in my project, When i decide to change...
Read more >
Global route prefixes with attribute routing in ASP.NET Web API
ASP.NET Web API allows you to provide a common route prefix for all the routes within a controller via RoutePrefixAttribute. This is obviously...
Read more >
Routing to controller actions in ASP.NET Core - Microsoft Learn
ASP.NET Core controllers use the Routing middleware to match the URLs of incoming requests and map them to actions. Route templates:.
Read more >
Global Routes for ASP.NET Core MVC - Ben Cull's Blog
The approach we'll take is to read all of our controller's routes and either combine our prefix with any existing routes, or create...
Read more >
Global route prefix in ASP.NET Core MVC (revisited)
In this case, api/v{version} will prefix every single route in your application. So you can now write controllers without any controller-level ...
Read more >

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