import { NestFactory } from '@nestjs/core'; import { ValidationPipe, Logger } from '@nestjs/common'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { ConfigService } from '@nestjs/config'; import { AppModule } from './app.module'; async function bootstrap() { const logger = new Logger('Bootstrap'); const app = await NestFactory.create(AppModule); const configService = app.get(ConfigService); const port = configService.get('PORT', 3005); const appName = configService.get('APP_NAME', 'reward-service'); // 全局验证管道 app.useGlobalPipes( new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true, }), ); // 跨域配置 app.enableCors(); // Swagger 配置 const config = new DocumentBuilder() .setTitle('Reward Service API') .setDescription('RWA榴莲女皇平台 - 权益奖励微服务 API 文档') .setVersion('1.0') .addBearerAuth() .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('api', app, document); await app.listen(port); logger.log(`${appName} is running on port ${port}`); logger.log(`Swagger documentation available at http://localhost:${port}/api`); } bootstrap();