nest
nest copied to clipboard
Nest crash when RouteConstraints is used without app versioning enabled
Is there an existing issue for this?
- [X] I have searched the existing issues
Current behavior
After some testing, there is an untested case that crashes Nest when using RouteConstraints and app versioning is not set in fastify context.
Related to: https://github.com/nestjs/nest/pull/12567
~/node_modules/@nestjs/platform-fastify/adapters/fastify-adapter.js:62
if (this.versioningOptions.type === common_1.VersioningType.MEDIA_TYPE) {
^
TypeError: Cannot read properties of undefined (reading 'type')
at Object.deriveConstraint (~/node_modules/@nestjs/platform-fastify/adapters/fastify-adapter.js:62:44)
at Constrainer.eval (eval at _buildDeriveConstraints (~/node_modules/find-my-way/lib/constrainer.js:168:34), <anonymous>:4:36)
at Constrainer.deriveConstraints (~/node_modules/find-my-way/lib/constrainer.js:62:30)
at Router.lookup (~/node_modules/find-my-way/index.js:526:42)
at Server.preRouting (~/node_modules/fastify/fastify.js:905:14)
at Server.emit (node:events:518:28)
at parserOnIncoming (node:_http_server:1137:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
Minimum reproduction code
Steps to reproduce are easy, no need repo
Steps to reproduce
- Add @RouteConstraints({ version: '1.2.x' }) to a route
- Do not enable app versioning
- Accessing to any route on app
Expected behavior
A catch with a warning to prevent user to enable app versioning before using RouteConstraints decorator. @Fcmam5 this maybe requires to add an additional test to catch this case.
Package
- [ ] I don't know. Or some 3rd-party package
- [ ]
@nestjs/common - [ ]
@nestjs/core - [ ]
@nestjs/microservices - [ ]
@nestjs/platform-express - [X]
@nestjs/platform-fastify - [ ]
@nestjs/platform-socket.io - [ ]
@nestjs/platform-ws - [ ]
@nestjs/testing - [ ]
@nestjs/websockets - [ ] Other (see below)
Other package
No response
NestJS version
10.3.6
Packages versions
"@nestjs/common": "10.3.6",
"@nestjs/core": "10.3.6",
"@nestjs/platform-fastify": "10.3.6",
Node.js version
20.12.1
In which operating systems have you tested?
- [X] macOS
- [ ] Windows
- [ ] Linux
Other
No response
@micalevisk please assign me this issue, I'll file a PR to add a warning if app versioning is not enabled
Would you like to create a PR for this issue?
Would you like to create a PR for this issue?
Yes, will do
Let's track this here https://github.com/nestjs/nest/pull/13536