52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { ValidationPipe, Logger } from '@nestjs/common';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import { AppModule } from './app.module';
|
|
|
|
async function bootstrap() {
|
|
const logger = new Logger('Bootstrap');
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
// 全局前缀
|
|
app.setGlobalPrefix('api/v1');
|
|
|
|
// 全局验证管道
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
transformOptions: { enableImplicitConversion: true },
|
|
}),
|
|
);
|
|
|
|
// CORS 配置
|
|
app.enableCors({
|
|
origin: '*',
|
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
|
credentials: true,
|
|
});
|
|
|
|
// Swagger API 文档
|
|
const config = new DocumentBuilder()
|
|
.setTitle('Planting Service API')
|
|
.setDescription('RWA 榴莲女皇平台认种服务 API')
|
|
.setVersion('1.0.0')
|
|
.addBearerAuth()
|
|
.addTag('认种订单', '认种订单相关接口')
|
|
.addTag('认种持仓', '认种持仓相关接口')
|
|
.addTag('健康检查', '服务健康检查接口')
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api/docs', app, document);
|
|
|
|
const port = process.env.APP_PORT || 3003;
|
|
await app.listen(port);
|
|
|
|
logger.log(`Planting Service is running on port ${port}`);
|
|
logger.log(`Swagger docs: http://localhost:${port}/api/docs`);
|
|
}
|
|
|
|
bootstrap();
|