Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware is not triggered when pass controller to consumer's forRoutes() #11833

Closed
5 of 15 tasks
ianzone opened this issue Jun 18, 2023 · 2 comments · Fixed by #11837
Closed
5 of 15 tasks

Middleware is not triggered when pass controller to consumer's forRoutes() #11833

ianzone opened this issue Jun 18, 2023 · 2 comments · Fixed by #11837
Labels
needs triage This issue has not been looked into

Comments

@ianzone
Copy link

ianzone commented Jun 18, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

this won't trigger the AuthMiddleware

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

this will trigger the AuthMiddleware

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

Minimum reproduction code

https://github.com/ianzone/nest-issue

Steps to reproduce

  1. pnpm i
  2. pnpm run dev
  3. go to localhost:3000/users

Expected behavior

AuthMiddleware get triggered and console logs out 'AuthMiddleware invoked...'

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

No response

Packages versions

[System Information]
OS Version : Linux 5.15
NodeJS Version : v18.16.0
PNPM Version : 8.6.2

[Nest CLI]
Nest CLI Version : 10.0.2

[Nest Platform Information]
platform-fastify version : 10.0.1
mapped-types version : 0.0.1
schematics version : 10.0.1
testing version : 10.0.1
common version : 10.0.1
core version : 10.0.1
cli version : 10.0.2

Node.js version

v18.16.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@ianzone ianzone added the needs triage This issue has not been looked into label Jun 18, 2023
@micalevisk
Copy link
Member

micalevisk commented Jun 19, 2023

that seems to be a regression introduce by PR #9809 (v10.0.0)

it looks like we can fix that by calling stripEndSlash on route.path here:

const isOverlapped = (v: { path: string; regex: RegExp }) => {
return route.path !== v.path && route.path.match(v.regex);
};

but I'm unsure if this is the right way to address that

@kamilmysliwiec
Copy link
Member

Let's track this here #11837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants