4

Explaining my code below: There are two middleware AuthenticationMiddleware, RequestFilterMiddleware which intervene ALL request methods.

My question is how to make RequestFilterMiddleware middleware only for GET method and AuthenticationMiddleware middleware for ALL request methods

app.module.ts

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(AuthenticationMiddleware, RequestFilterMiddleware)
      .forRoutes({ path: '/**', method: RequestMethod.ALL });
  }
}
Vignesh
  • 234
  • 1
  • 3
  • 12

1 Answers1

16

That should do it, no?

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(AuthenticationMiddleware)
      .forRoutes({ path: '/**', method: RequestMethod.ALL });
    consumer
      .apply(RequestFilterMiddleware)
      .forRoutes({ path: '/**', method: RequestMethod.GET });
  }
}
tpschmidt
  • 2,479
  • 2
  • 17
  • 30