2023-11-17 16:18:24 +00:00
|
|
|
import { NestFactory } from '@nestjs/core';
|
|
|
|
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
|
|
|
|
|
2023-12-12 08:40:19 +00:00
|
|
|
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'],
|
|
|
|
});
|
|
|
|
|
2023-11-20 08:35:17 +00:00
|
|
|
app.setGlobalPrefix('api');
|
|
|
|
|
2023-12-12 08:40:19 +00:00
|
|
|
// 使validator的约束可以使用nestjs的容器
|
|
|
|
useContainer(app.select(AppModule), {
|
|
|
|
fallbackOnErrors: true,
|
|
|
|
});
|
|
|
|
|
2023-11-17 16:18:24 +00:00
|
|
|
await app.listen(2333, () => {
|
2023-11-20 08:35:17 +00:00
|
|
|
console.log('api: http://localhost:2333/api');
|
2023-11-17 16:18:24 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
bootstrap();
|