main.ts 749 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * 应用入口 - NestJS 引导,全局 /v1 前缀,端口从环境变量读取
  3. */
  4. import { NestFactory } from '@nestjs/core';
  5. import { ValidationPipe } from '@nestjs/common';
  6. import { AppModule } from './app.module';
  7. async function bootstrap() {
  8. const app = await NestFactory.create(AppModule);
  9. // 全局参数校验
  10. app.useGlobalPipes(
  11. new ValidationPipe({
  12. whitelist: true,
  13. forbidNonWhitelisted: true,
  14. transform: true,
  15. }),
  16. );
  17. // 全局 API 前缀
  18. app.setGlobalPrefix('v1');
  19. // CORS 开启(后续收紧)
  20. app.enableCors();
  21. const port = process.env['PORT'] ?? 8080;
  22. await app.listen(port);
  23. console.log(`🚀 DoTouch.AI API running on http://localhost:${port}/v1`);
  24. }
  25. void bootstrap();