요약
Incoming request
Globally bound middleware
Module bound middleware
Global guards
Controller guards
Route guards
Global interceptors (pre-controller)
Controller interceptors (pre-controller)
Route interceptors (pre-controller)
Global pipes
Controller pipes
Route pipes
Route parameter pipes
Controller (method handler)
Service (if exists)
Route interceptor (post-request)
Controller interceptor (post-request)
Global interceptor (post-request)
Exception filters (route, then controller, then global)
Server response
middleware
- global 로 바인딩된 middleware 제일 먼저 실행
- module 로 바인딩된 미들웨어 실행
guard
- global guard, controller guard, route guard 순서로 실행
- 아래 예제에선 Guard1 Guard2 Guard3 순서
@UseGuards(Guard1, Guard2)
@Controller('cats')
export class CatsController {
constructor(private catsService: CatsService) {}
@UseGuards(Guard3)
@Get()
getCats(): Cats[] {
return this.catsService.getCats();
}
}
intercepter
- middleware 와 동일한 패턴
- standard global, controller, route 순서
- 응답시에는 반대로 route, controller, global 순서
Pipe
- global, controller, route 순서
@UsePipes
로 적용되는 파이프는 FIFO 로 적용
- 아래 예제에서는
GeneralValidationPipe
가 Query, Param, Body 순서로 적용되고,
- 그 다음 RouteSpecificPipe 가 동일한 순서로 적용
@UsePipes(GeneralValidationPipe)
@Controller('cats')
export class CatsController {
constructor(private catsService: CatsService) {}
@UsePipes(RouteSpecificPipe)
@Patch(':id')
updateCat(
@Body() body: UpdateCatDTO,
@Param() params: UpdateCatParams,
@Query() query: UpdateCatQuery,
) {
return this.catsService.updateCat(body, params, query);
}
}
Filter
- route bounding, controller, global 순서
reference