When sending OPTIONS
request, middleware doesn't get triggered.
export class AppModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(CorsMiddleware).forRoutes({
path: "*",
method: RequestMethod.OPTIONS
});
}
}
If I were to change RequestMethod.OPTIONS
to RequestMethod.ALL
, it would get triggered on all requests, except OPTIONS
.
Is that by design? If so, how do we workaround it when we want to specifically trigger middleware for OPTIONS
request.
Example middleware:
@Injectable()
export class CorsMiddleware implements NestMiddleware {
resolve(...args: any[]): MiddlewareFunction {
return (req, res, next) => {
console.log("testing ????", req.method);
next && next();
};
}
}