3r-xidongdong-nestjs/src/main.ts

27 lines
703 B
TypeScript
Raw Normal View History

2023-11-17 16:18:24 +00:00
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { useContainer } from 'class-validator';
2023-11-17 16:18:24 +00:00
import { AppModule } from '@/app.module';
const bootstrap = async () => {
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter(), {
cors: true,
logger: ['error', 'warn'],
});
app.setGlobalPrefix('api');
// 使validator的约束可以使用nestjs的容器
useContainer(app.select(AppModule), {
fallbackOnErrors: true,
});
2023-11-17 16:18:24 +00:00
await app.listen(2333, () => {
console.log('api: http://localhost:2333/api');
2023-11-17 16:18:24 +00:00
});
};
bootstrap();