fix: mount app/server as /app/app-server dir + smart loader (single-file shadow mount was unreliable)
This commit is contained in:
@@ -16,7 +16,7 @@ services:
|
||||
- ./www:/app/www:ro # 前端直读仓库目录:git pull 即生效,无需重建镜像
|
||||
- ./src:/app/src:ro # 后端源码直读(零依赖纯 .mjs)
|
||||
- ./schema.sql:/app/schema.sql:ro
|
||||
- ../app/server/db.mjs:/app/src/app-commands.mjs:ro # 命令层以仓库数据层为准
|
||||
- ../app/server:/app/app-server:ro # 命令层整目录挂载(避免单文件嵌套遮蔽的不可靠行为)
|
||||
environment:
|
||||
- REGISTER_ENABLED=true
|
||||
- INVITE_CODE=please-change-me # 多用户:注册须携带此邀请码(留空则不校验)
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
// 本地开发:直接引用仓库内的命令层(与桌面端单一数据源)
|
||||
// Docker 构建:此文件被 app/server/db.mjs 覆盖(见 Dockerfile),保证同源
|
||||
export { createAppCommands } from '../../app/server/db.mjs';
|
||||
// 命令层加载器:自动探测运行环境
|
||||
// - 容器: compose 将 ../app/server 挂载到 /app/app-server(目录级挂载,稳定可靠)
|
||||
// - 本地开发: 引用仓库内 app/server/db.mjs(与桌面端单一数据源)
|
||||
import { existsSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import path from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
const candidates = [
|
||||
process.env.APP_COMMANDS_PATH,
|
||||
path.join(here, '..', 'app-server', 'db.mjs'), // 容器
|
||||
path.join(here, '..', '..', 'app', 'server', 'db.mjs'), // 本地仓库
|
||||
].filter(Boolean);
|
||||
const target = candidates.find((p) => existsSync(p));
|
||||
if (!target) throw new Error('找不到命令层 db.mjs,尝试过: ' + candidates.join(', '));
|
||||
|
||||
const mod = await import(pathToFileURL(target).href);
|
||||
export const createAppCommands = mod.createAppCommands;
|
||||
export default mod;
|
||||
|
||||
Reference in New Issue
Block a user