Nest: consumer.apply(middleware).forRoutes(pathString) not working

Created on 16 May 2018  路  6Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

in the .module - consumer.apply([middlewares]).forRoutes('get/stuff');

At the moment, the middlewares don't get invoked when we pass a single route as a string, it only works with a controller.. So we are unable to configure middlewares for a certain route..

Expected behavior

The middlewares should be called before the controller.

core potential issue 馃挃

Most helpful comment

Hey @bojidaryovchev,
Thanks for reporting, I'll take a look at it 馃憤

All 6 comments

Hey @bojidaryovchev,
Thanks for reporting, I'll take a look at it 馃憤

Fixed in v5.0.1

@kamilmysliwiec I'm seeing this issue again in v5.7.4. Middleware is invoked with a controller is passed but not when a string is passed.

This works:

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(LoggerMiddleware).forRoutes(MyController);
  }
}

But this doesn't:

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(LoggerMiddleware).forRoutes('*');
  }
}

@felangel could you please create a separate issue? :)

@kamilmysliwiec thanks for the quick reply! I saw the issue was fixed in the latest release 馃憤馃帀馃挴

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.

Was this page helpful?
0 / 5 - 0 ratings