fix: mount app/server as /app/app-server dir + smart loader (single-file shadow mount was unreliable)
This commit is contained in:
@@ -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