Performance: Controller decorator
MEDIUM IMPACT
This affects the routing setup and initial request handling speed in a NestJS application.
import { Controller, Get } from '@nestjs/common'; @Controller('api') export class AppController { @Get('users') getUsers() { // logic } @Get('products') getProducts() { // logic } @Get('orders') getOrders() { // logic } }
import { Controller, Get } from '@nestjs/common'; @Controller('') export class AppController { @Get('users') getUsers() { // logic } @Get('products') getProducts() { // logic } @Get('orders') getOrders() { // logic } }
| Pattern | Routing Checks | Request Latency | Code Complexity | Verdict |
|---|---|---|---|---|
| Empty string prefix in @Controller | High (all routes at root) | Higher latency due to more checks | Moderate | [X] Bad |
| Specific prefix in @Controller (e.g., 'api') | Lower (grouped routes) | Lower latency with faster matching | Moderate | [OK] Good |