Q:

How to apply middleware in nest.js for module other than ApplicationModule?

Im trying to apply middleware based on config like so:
export class UsersModule implements NestModule{
  configure(consumer: MiddlewaresConsumer): void {
    const authRoutes = UsersController.getAuthRoutes();
    consumer
      .apply(AuthMiddleware)
      .forRoutes(...authRoutes);
  }
}

method getAuthRoutes is static:
  public static getAuthRoutes(){
    return [
      { path: `/api/users`, method: RequestMethod.ALL},
    ];
  }

My AuthMIddleware is pretty basic:
@Middleware()
export class AuthMiddleware implements NestMiddleware {
  constructor(
    @Inject(constants.logger) private logger: Winston,
  ){}

  resolve(...args: any[]): ExpressMiddleware {
    // return passport.authenticate('jwt', { session: false });
    return (req, res, next) => {
      this.logger.debug('AuthMiddleware');
      next();
    };
  }
}

It just logs line in console. Im trying to access via get request /api/users, im getting list of users, but no AuthMiddleware message in console. Any advices?

A:

See my issue here. Its just misunderstanding of documentation.

