从模块连接时,NestJS 类或功能中间件不会运行。它也不适用于单个路径、控制器或每个路径。从 main.ts 连接功能中间件工作正常。
//main.ts
import { ValidationPipe } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'
import { AppModule } from './app.module'
declare const module: any
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter())
app.useGlobalPipes(new ValidationPipe())
await app.listen(2100)
if (module.hot) {
module.hot.accept()
module.hot.dispose(() => app.close())
}
}
bootstrap()
Run Code Online (Sandbox Code Playgroud)
//app.module.ts
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'
import { AuthMiddleware } from './middleware/auth.middleware'
import { UserModule } from './user/user.module' …Run Code Online (Sandbox Code Playgroud)