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

nestjs/core@8.4.1 breaks :param in globalPrefix #9776

Closed
4 of 15 tasks
minju-s opened this issue Jun 14, 2022 · 7 comments
Closed
4 of 15 tasks

nestjs/core@8.4.1 breaks :param in globalPrefix #9776

minju-s opened this issue Jun 14, 2022 · 7 comments

Comments

@minju-s
Copy link

minju-s commented Jun 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When setting a parameter in app.setGlobalPrefix(':prefix') it is only available in a controller and not in a middleware.
In version 8.4.0 it works in the middleware too. You can test it if you set 8.4.0 manually in the package.json.

Minimum reproduction code

https://github.com/minju-s/nestjs-global-prefix-test

Steps to reproduce

  1. npm ci
  2. npm start
  3. goto http://localhost:3000/test/app
  4. console outputs undefined

Expected behavior

  1. npm ci
  2. npm start
  3. goto http://localhost:3000/test/app
  4. console outputs test

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

8.4.1

Packages versions

"@nestjs/core": "8.4.1"

Node.js version

16.15.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@minju-s minju-s added the needs triage This issue has not been looked into label Jun 14, 2022
@minju-s
Copy link
Author

minju-s commented Jun 15, 2022

The problematic code stems from the middleware-module.ts file of this commit 1ae72e1.
The condition ['*', '/*', '(.*)', '/(.*)'].includes(path) in line 279 evaluates to true as the path is /*.

Using this knowledge I changed the code to apply my middleware from path: '*' to path: '*/'. This solves the problem, but it is a workaround, so it would be nice to have it fixed in the future.

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@micalevisk micalevisk removed the needs triage This issue has not been looked into label Sep 25, 2022
@hayawata3626
Copy link

@kamilmysliwiec
Nice to meet you.
I don't know which part of the code to modify, but I'd like to do it when I have time.

@CodyTseng
Copy link
Contributor

In my humble opinion, the problem is that the meaning of .forRoutes({ path: '*', method: RequestMethod.ALL }); is defferent before and after the commit 1ae72e1.

Before this commit, the effect is equivalent to .use('${globalPrefix}/*', MiddlewareFn).

After this commit, the effect is equivalent to .use('*', MiddlewareFn). This is to solve #9124.

So if the golbal prefix contains :param, It will cause the two versions to have different results. I propose to add an isGlobal option instead of path: '*' to implement global middleware.

@pratik-codes
Copy link

Has anyone picked it up can I try to give it a shot?

@micalevisk
Copy link
Member

@pratik-codes

image

@kamilmysliwiec
Copy link
Member

Let's track this here #10390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants