2026-09-17 19:14:41 +08:00
|
|
|
// services/api/src/main-cn.ts
|
|
|
|
|
// cn-app 部署入口(P1a 仅此一个 API 入口)。构建产物 dist/main-cn.js 由根 dev:api /
|
|
|
|
|
// 生产启动命令运行;env 一律来自进程环境(根 dotenv-cli 注入),此处不读文件。
|
|
|
|
|
import 'reflect-metadata';
|
|
|
|
|
import { type INestApplication } from '@nestjs/common';
|
|
|
|
|
import { NestFactory } from '@nestjs/core';
|
|
|
|
|
import { Logger } from 'nestjs-pino';
|
|
|
|
|
import { AppCnModule } from './app-cn.module';
|
2026-09-17 20:54:30 +08:00
|
|
|
import { API_PREFIX } from './shared/constants';
|
2026-09-17 19:14:41 +08:00
|
|
|
|
|
|
|
|
async function bootstrap(): Promise<void> {
|
|
|
|
|
const app = await NestFactory.create<INestApplication>(AppCnModule, {
|
|
|
|
|
bufferLogs: true,
|
|
|
|
|
});
|
|
|
|
|
app.useLogger(app.get(Logger));
|
2026-09-17 20:54:30 +08:00
|
|
|
app.setGlobalPrefix(API_PREFIX);
|
2026-09-17 19:14:41 +08:00
|
|
|
const corsOrigins = (process.env.CORS_ORIGINS ?? 'http://localhost:5173')
|
|
|
|
|
.split(',')
|
|
|
|
|
.map((origin) => origin.trim())
|
|
|
|
|
.filter((origin) => origin !== '');
|
|
|
|
|
app.enableCors({ origin: corsOrigins });
|
|
|
|
|
const port = Number.parseInt(process.env.PORT ?? '', 10) || 8080;
|
|
|
|
|
await app.listen(port);
|
|
|
|
|
app.get(Logger).log(`api-cn listening on port ${port}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void bootstrap();
|