60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import { AppModule } from './app.module';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
// 全局验证管道
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
transformOptions: {
|
|
enableImplicitConversion: true,
|
|
},
|
|
}),
|
|
);
|
|
|
|
// CORS 配置
|
|
app.enableCors({
|
|
origin: true,
|
|
credentials: true,
|
|
});
|
|
|
|
// API 前缀
|
|
app.setGlobalPrefix('api/v1');
|
|
|
|
// Swagger 文档配置
|
|
const config = new DocumentBuilder()
|
|
.setTitle('Leaderboard Service API')
|
|
.setDescription('RWA 龙虎榜微服务 API 文档')
|
|
.setVersion('1.0')
|
|
.addBearerAuth()
|
|
.addTag('健康检查', '服务健康状态检查')
|
|
.addTag('龙虎榜', '龙虎榜排名相关接口')
|
|
.addTag('龙虎榜配置', '龙虎榜配置管理(管理员)')
|
|
.addTag('虚拟账户', '虚拟账户管理(管理员)')
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api/docs', app, document);
|
|
|
|
const port = process.env.PORT || 3007;
|
|
await app.listen(port);
|
|
|
|
console.log(`
|
|
====================================
|
|
🚀 Leaderboard Service 已启动
|
|
====================================
|
|
- 端口: ${port}
|
|
- 环境: ${process.env.NODE_ENV || 'development'}
|
|
- API 文档: http://localhost:${port}/api/docs
|
|
====================================
|
|
`);
|
|
}
|
|
|
|
bootstrap();
|