Utilizing NestJS
and Angular 2
, I have noticed that both frameworks have a similar approach when it comes to working with Interceptors
. I am currently looking for the best practice to identify specific requests in order to perform additional tasks.
When declaring an Interceptor
that will be listening to a specific Controller
in NestJS
, I need to follow this logic:
@UseInterceptors(ObjectsInterceptor)
@Controller('objects')
export class ObjectsController {
@Get()
async findAll(): Promise<ObjectDto[]> {
// Request that should be intercepted
...
}
@Get(':slug')
async findOne(@Params('slug') slug: string): Promise<ObjectDto> {
// Request that should not be intercepted
...
}
}
Within the Interceptor
:
@Injectable()
export class ObjectsInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any> {
// Implement some logic to detect specific request
return next.handle();
}
}
It seems like I might be approaching the solution to my problem in the wrong way