nest icon indicating copy to clipboard operation
nest copied to clipboard

[Bug] Middleware forRoutes object.method: 'POST' only accepts numeric values

Open JulianRuhrDev opened this issue 9 years ago • 3 comments

Hi,

I found a bug regarding the application of middleware using the object notation.

I got the following code here:

export class UserModule {
  public configure(consumer: MiddlewaresConsumer): void {
    consumer.apply(JwtAuthenticationStrategy).forRoutes(UserController);
    consumer.apply(UserValidationMiddleware).forRoutes({path: '/user', method: 'GET'});
    consumer.apply(UserGenerateValidationMiddleware).forRoutes({path: '/user/generate', method: 'POST'});
  }
}
  • The application of the JwtAuthenticationMiddleware is working
  • The application of the UserValidationMiddleware is working
  • The application of the UserGenerateValidationMiddleware is NOT working!

The last middleware is not triggered when entering the route. However if I change the method value to the following it works:

export class UserModule {
  public configure(consumer: MiddlewaresConsumer): void {
    consumer.apply(JwtAuthenticationStrategy).forRoutes(UserController);
    consumer.apply(UserValidationMiddleware).forRoutes({path: '/user', method: 'GET'});
    consumer.apply(UserGenerateValidationMiddleware).forRoutes({path: '/user/generate', method: 1});
  }
}

I changed the string POST to the numeric value 1 which seems to represent the POST method.

JulianRuhrDev avatar May 19 '17 09:05 JulianRuhrDev

Hi @JulianBiermann, It is not a bug. You should use RequestMethod.POST instead of plain strings ('POST').

kamilmysliwiec avatar May 19 '17 09:05 kamilmysliwiec

Thanks for letting me know.

JulianRuhrDev avatar May 19 '17 11:05 JulianRuhrDev

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Sep 25 '19 13:09 lock[bot]