27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
|
|
// 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';
|
||
|
|
|
||
|
|
async function bootstrap(): Promise<void> {
|
||
|
|
const app = await NestFactory.create<INestApplication>(AppCnModule, {
|
||
|
|
bufferLogs: true,
|
||
|
|
});
|
||
|
|
app.useLogger(app.get(Logger));
|
||
|
|
app.setGlobalPrefix('v1');
|
||
|
|
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();
|