Answer the question
In order to leave comments, you need to log in
How to add 2 different intermediaries to different routes in NestJS inside one module?
The documentation only describes how to add multiple alternate middleware to the same routes https://docs.nestjs.com/middleware#multiple-middleware
But I need to add 2 middleware to 2 independent routes from 2 controllers.
Now I have this code
export class ImageModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(AwsImagesMiddleware)
.forRoutes('dashboard/images/upload-images');
}
}
Answer the question
In order to leave comments, you need to log in
Yes, everything was easier. The forRoutes method returns the consumer again.
So just like this
export class ImageModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(AwsImagesMiddleware)
.forRoutes('dashboard/images/upload-images')
.apply(AwsAvatarsMiddleware)
.forRoutes('images/upload-avatar');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question