nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.91k stars 7.55k forks source link

NestJS/ Fastify Controller wildcard not working as intended #9299

Closed MarcoLeko closed 2 years ago

MarcoLeko commented 2 years ago

Is there an existing issue for this?

Current behavior

When using NestJS with the fastify adapter and trying to apply a wildcard to a controller route, it does not get picked up as a regex. Applying the hint from the documentation did not help at all:

WARNING The fastify package uses the latest version of the path-to-regexp package, which no longer supports wildcard asterisks . Instead, you must use parameters (e.g., (.), :splat*).

What I would like to achieve for my cat controller to match any request call that at least contains /cat in the url. So requests that should hit are:

By doing something like this:

// cat.controller.ts
@Controller('(.*)/cat/')
export class CatController {
    @Get()
    @Head()
    @Render('cat')
    root(@Param('catId') catId: string) {
        return {
            catId,
        };
    }
}

I've provided a minimal reproducable stackblitz env for this: Stackblitz

Minimum reproduction code

https://stackblitz.com/edit/nestjs-starter-demo-qkygfu?file=src/cat.controller.ts

Steps to reproduce

No response

Expected behavior

The expected behaviour is that the wildcard logic should apply for the given controllers.

Package

Other package

No response

NestJS version

8.26

Packages versions

{
        "@nestjs/common": "^8.2.6",
        "@nestjs/config": "^1.2.0",
        "@nestjs/core": "^8.2.6",
        "@nestjs/platform-fastify": "^8.3.1",
        "@nestjs/swagger": "^5.1.5",
        "@nestjs/terminus": "^7.2.0",
        "@nestjs/typeorm": "^8.0.3"
}

Node.js version

14.14

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 2 years ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.