[Bug] Middleware forRoutes object.method: 'POST' only accepts numeric values
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.
Hi @JulianBiermann,
It is not a bug. You should use RequestMethod.POST instead of plain strings ('POST').
Thanks for letting me know.
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.