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.9k stars 7.55k forks source link

Controller prefix not working, can't create route with given prefix #4028

Closed ichn-hu closed 4 years ago

ichn-hu commented 4 years ago

Bug Report

Current behavior

not-working

Input Code

Use nest n proj to create a blank project and change src/app.controller.ts into (just add prefixes)

import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller('cat')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('good')
  getHello(): string {
    return this.appService.getHello();
  }
}

Expected behavior

getHello routed to /cat/good, however it is routed to /good and the cat prefix is ignored.

Environment

➜  project-name git:(master) ✗ nest -v
6.14.2

Nest version: 6.14.2


For Tooling issues:
- Node version: v13.8.0  
- Platform:  Linux 

Others:

bfg-coding commented 4 years ago

So you get the result you are expecting at the /good endpoint but not the /cat/good endpoint?

kamilmysliwiec commented 4 years ago

Please, provide a minimal repository which reproduces your issue.

ichn-hu commented 4 years ago

So you get the result you are expecting at the /good endpoint but not the /cat/good endpoint?

I am expecting /cat/good, but get /good.

ichn-hu commented 4 years ago

Please, provide a minimal repository which reproduces your issue.

Sure, please take a look, https://github.com/ichn-hu/nestjs-route-bug-reproduce

ichn-hu commented 4 years ago

https://github.com/ichn-hu/nestjs-route-bug-reproduce/blob/master/src/app.controller.ts

This is the only modified file from nest n proj, I didn't do anything with other files. I was working on another project using nestjs but found the route not working and could reproduce it from the bare bone nest n proj.

ichn-hu commented 4 years ago

My fault, it is actually routed to /good/cat... The logged information is misleading, it reads

[Nest] 13871   - 02/11/2020, 9:42:45 AM   [NestFactory] Starting Nest application...
[Nest] 13871   - 02/11/2020, 9:42:45 AM   [InstanceLoader] AppModule dependencies initialized +32ms
[Nest] 13871   - 02/11/2020, 9:42:45 AM   [RoutesResolver] AppController {/cat}: +11ms
[Nest] 13871   - 02/11/2020, 9:42:45 AM   [RouterExplorer] Mapped {/good, GET} route +3ms
[Nest] 13871   - 02/11/2020, 9:42:45 AM   [NestApplication] Nest application successfully started +2ms

When I saw Mapped {/good, GET}, I thought it's routed to /good, but it is actually /cat/good as expected.

Perhaps this issue can be useful from a starter's perspective, and I would suggest some change here but since my problem is solved, I am closing it.

Thanks @JustinR93 and @kamilmysliwiec for comment.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.