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

route exclusion from the setGlobalPrefix not taken in account when enableVersioning is set #10215

Closed
3 of 15 tasks
cperuzzi opened this issue Sep 1, 2022 · 8 comments
Closed
3 of 15 tasks
Labels
needs triage This issue has not been looked into

Comments

@cperuzzi
Copy link

cperuzzi commented Sep 1, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Hi folks,

When you create an API and set the global prefix to something with a configuration containing exclusion like this
app.setGlobalPrefix('api', { exclude: [ "/my-route", ], });

the 'my-route' is not taken in account at all if I enable the API versioning like this :

app.enableVersioning({ type: VersioningType.URI, defaultVersion: '1', });

Minimum reproduction code

https://github.com/cperuzzi/nest-routing-issue

Steps to reproduce

  1. npm install
  2. npm start
  3. use the route http://localhost:3000/api/v1/route => it returns something
  4. use the route http://localhost:3000/route => 404

Expected behavior

when a route is excluded in the global prefix it should be excluded even if the route versioning is enabled

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

9.x

Packages versions

[Nest CLI]
Nest CLI Version : 9.1.1 

[Nest Platform Information]
platform-express version : 9.0.11
schematics version       : 9.0.2
testing version          : 9.0.11
common version           : 9.0.11
core version             : 9.0.11
cli version              : 9.1.1

Node.js version

16.17.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@cperuzzi cperuzzi added the needs triage This issue has not been looked into label Sep 1, 2022
@quangtran88
Copy link
Contributor

quangtran88 commented Sep 2, 2022

I think the expected route should be http://localhost:3000/v1/route because setGlobalPrefix and enableVersioning should behave independently. When set the exclude option only for setGlobalPrefix but not for enableVersioning, then the versioning should be applied normally. I suggest the current behavior should be fixed in this way but I don't know if it'll break any existing apps out there.

@cperuzzi
Copy link
Author

cperuzzi commented Sep 2, 2022

one request then is to be able to exclude the same route from the versioning as well

@gitSambhal
Copy link

Try adding

  @Version(VERSION_NEUTRAL)

to the controller method.

@cperuzzi
Copy link
Author

cperuzzi commented Sep 5, 2022

When I add VERSION_NEUTRAL it does have the behavior of putting the excluded route to the http://localhost:3000/v1/route but in this case, I have to add the v1 version in all of my controllers explicitly.

It would be great just to have the possibility to exclude a specific route (or a list) from all the global route prefixes.

@gitSambhal
Copy link

@cperuzzi I think you have added the version_neutral at the controller level, you need to add it to the function level only.

@ricardodantas
Copy link

This is not working for me as well.

@crice88
Copy link

crice88 commented Apr 4, 2023

My excluded routes are completely hosed right now when version is bumped from 9.2.1 to latest. We have a similar setup to OP.

@kamilmysliwiec
Copy link
Member

Let's track this here #11650

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

No branches or pull requests

6 participants