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); // Global prefix app.setGlobalPrefix('api/v1'); // Validation 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 const config = new DocumentBuilder() .setTitle('Identity Service API') .setDescription('RWA用户身份服务API') .setVersion('2.0.0') .addBearerAuth() .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('api/docs', app, document); const port = process.env.APP_PORT || 3000; await app.listen(port); console.log(`Identity Service is running on port ${port}`); console.log(`Swagger docs: http://localhost:${port}/api/docs`); } bootstrap();