How can set many globalprefix for nestjs project

Viewed 23

I want set many Global Prefix for my app like this :

admin/products
admin/users
admin/...

api/products
api/search
api/...

shop/products
shop/cart
shop/...

i can set one globalprefix into main.ts app.setGlobalPrefix('api')

1 Answers

Use app.setGlobalPrefix('api') only for a global prefix. If you want the same prefix for many controllers, you must write it in each controller, like:

@Controller('shop/products')

You can also define a constant somewhere and reuse it every time:

const shopPrefix: string = 'shop';    
@Controller(`${shop}/products`)
Related