/** * 总启动器 * * 职责(遵循《后端目录规范》第八节): * - 加载环境变量(dotenv.config()) * - 启动 PC 端服务(单端口,所有模块路由统一挂载) * - 启动 Mobile 端服务(单端口) * - 处理进程级事件 * * 端口规划: * 3101 — PC 端(11 个业务模块共用一个 Express App) * 3201 — Mobile 端(chat 等模块) * * 前端只需配置两个 baseURL: * PC_BASE_URL = http://localhost:3101/api * MOBILE_BASE_URL = http://localhost:3201/api */ import { config } from 'dotenv'; import { startPcServer } from './apps/pc/health/server.js'; import { startMobileChatServer } from './apps/mobile/chat/server.js'; // 必须在读取任何 process.env 之前调用 config(); console.log('==========================================='); console.log(' Lami Base — 后端服务启动中...'); console.log('==========================================='); // PC 端(3101)—— 所有模块共用一个端口 startPcServer(); // Mobile 端(3201)—— AI 聊天等 startMobileChatServer(); // ---- 进程事件 ---- process.on('SIGINT', () => { console.log('\n收到 SIGINT,正在退出...'); process.exit(0); }); process.on('SIGTERM', () => { console.log('\n收到 SIGTERM,正在退出...'); process.exit(0); }); process.on('uncaughtException', (error) => { console.error('未捕获的异常:', error); process.exit(1); }); process.on('unhandledRejection', (reason) => { console.error('未处理的 Promise 拒绝:', reason); });