没有在nestjs中映射控制器方法



我有一个名为AuthModule的nestjs模块

import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersEntity } from './user-auth-credentials.entity';
import { UsersRepository } from './users.repository';
import { AuthController } from './auth.controller';
@Module({
imports: [TypeOrmModule.forFeature([UsersRepository])],
controllers: [AuthController],
providers: [AuthService],
})
export class AuthModule {}
a controller called **AuthController**.
import { Controller, Get } from '@nestjs/common';
import { AuthService } from './auth.service';
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
@Get()
findAll() {
return 'Hello World';
}
}

控制器findAll中的方法作为一个例子,在编译过程中没有被映射,如下面npm run start:dev的输出所示。

[12:36:39] File change detected. Starting incremental compilation...
[12:36:39] Found 0 errors. Watching for file changes.
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [NestFactory] Starting Nest application...
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmModule dependencies initialized +122ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +73ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] AuthModule dependencies initialized +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [InstanceLoader] TeachersModule dependencies initialized +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RoutesResolver] AppController {/}: +7ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/, GET} route +4ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RoutesResolver] TeachersController {/teachers}: +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers, GET} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers/id, GET} route +2ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers, POST} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers/id, PATCH} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RouterExplorer] Mapped {/teachers/id, DELETE} route +1ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [RoutesResolver] AuthController {/auth}: +0ms
[Nest] 4262  - 09/03/2022, 12:36:40     LOG [NestApplication] Nest application successfully started +4ms

当我使用失眠访问路线时,我会得到这个

失眠的输出

有什么事情我做得不对吗?

您的代码看起来不错,但输出没有显示任何Mapped {/auth, GET}。我想说,您可能正在运行旧版本的代码(并没有findAll方法(

尝试rm -rf dist,然后重新启动它。

最新更新