// 必须为首个 import:进程时区对齐要先于其余 import 的模块体副作用执行(见该文件注释) import './config/process-timezone.js'; import 'reflect-metadata'; import { NestFactory } from '@nestjs/core'; import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify'; import { AppModule } from './app.module.js'; import { loadConfig } from './config/app-config.js'; import { loadTrustedProxyAddresses } from './config/trusted-proxy.js'; import { createMaoApp } from './create-app.js'; import { fastifyLoggerOptions, installStructuredConsole, StructuredNestLogger } from './common/structured-logger.js'; installStructuredConsole(); async function bootstrap(): Promise { const cfg = loadConfig(); const adapter = new FastifyAdapter({ logger: fastifyLoggerOptions, trustProxy: loadTrustedProxyAddresses(), bodyLimit: 52 * 1024 * 1024, }); const nestApp = await NestFactory.create(AppModule, adapter, { bodyParser: false, logger: new StructuredNestLogger(), }); const fastify = nestApp.getHttpAdapter().getInstance(); const mao = await createMaoApp(cfg, fastify as never); const port = cfg.server.port; await nestApp.listen(port, '0.0.0.0'); console.info(`Mao TS backend listening on ${port} (context-path ${cfg.server.servlet.contextPath})`); const shutdown = async (): Promise => { await mao.close().catch(() => undefined); await nestApp.close().catch(() => undefined); process.exit(0); }; process.on('SIGINT', () => { void shutdown(); }); process.on('SIGTERM', () => { void shutdown(); }); } void bootstrap().catch((err) => { console.error('Failed to start Mao TS backend', err); process.exit(1); });