启动装配
入口:src/app.js。
顺序
validateEnv()— 校验根目录环境变量- 创建 Fastify(日志配置来自
utils/logger.js) setupDatabase(fastify)— 挂载fastify.pgfastify.decorate('env', env)— 供路由/服务读取路径等- 注册
health_router - 注册
@fastify/static(root: env.public_path) - 注册
legacy_router - 注册
v3_router(prefix: '/v3') setErrorHandler— 统一失败体{ message, data: null }listen(PORT或 3000,0.0.0.0)SIGINT/SIGTERM时关闭日志流并fastify.close()
js
await setupDatabase(fastify);
fastify.decorate('env', env);
await fastify.register(health_router);
await fastify.register(fastifyStatic, { root: env.public_path, prefix: '/' });
await fastify.register(legacy_router);
await fastify.register(v3_router, { prefix: '/v3' });本文件不包含业务 SQL。