import { NestFactory } from '@nestjs/core'; import { ValidationPipe } from '@nestjs/common'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { NestExpressApplication } from '@nestjs/platform-express'; import { join } from 'path'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableShutdownHooks(); const uploadDir = process.env.UPLOAD_DIR || join(__dirname, '..', '..', 'uploads'); app.useStaticAssets(uploadDir, { prefix: '/uploads/' }); app.setGlobalPrefix('api'); app.enableCors({ origin: true, credentials: true }); app.useGlobalPipes( new ValidationPipe({ whitelist: true, transform: true, forbidNonWhitelisted: true, }), ); const config = new DocumentBuilder() .setTitle('TheBet365 API') .setDescription('足球投注平台 MVP API') .setVersion('1.0') .addBearerAuth() .build(); SwaggerModule.setup('api/docs', app, SwaggerModule.createDocument(app, config)); const port = process.env.PORT || 3000; await app.listen(port); console.log(`API running on http://localhost:${port}`); console.log(`Swagger docs: http://localhost:${port}/api/docs`); } bootstrap();