fix: 修复 Rust OnlyOffice 附件打开链路
This commit is contained in:
+33
-23
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 同时热启动前端、FastAPI,以及按需启用的 Celery。
|
||||
* 热启动 mnote-web 单入口,以及按需启用的 FastAPI / Celery。
|
||||
* 可使用以下环境变量调整行为:
|
||||
* - FRONTEND_CMD:覆盖历史 Next 启动命令,仅在显式启用 legacy compat 或跳过 Rust gateway 时生效
|
||||
* - BACKEND_CMD:覆盖 FastAPI 启动命令,默认为 "python -m uvicorn app.main:app --reload --port 8000"
|
||||
* - ENABLE_BACKEND:设为 "1" or "true" 时启用默认 FastAPI 后端
|
||||
* - BACKEND_CMD:覆盖 FastAPI 启动命令;设置后即视为显式启用后端
|
||||
* - SKIP_BACKEND:设为 "1" or "true" 可强制跳过 FastAPI 后端
|
||||
* - ENABLE_CELERY:设为 "1" or "true" 时启用默认 Celery worker
|
||||
* - CELERY_CMD:覆盖 Celery 启动命令;设置后即视为显式启用 Celery
|
||||
* - CELERY_POOL:只在 CELERY_CMD 未覆盖时生效,设置 Celery worker pool;Windows 默认 "solo",其他平台默认使用 Celery 自身默认值
|
||||
@@ -13,7 +15,7 @@
|
||||
* - REDIS_URL:仅用于探测 Redis 是否就绪,默认 "redis://localhost:6379/0"
|
||||
* - SKIP_CELERY:设为 "1" or "true" 可强制跳过 Celery。
|
||||
* - MNOTE_WEB_SKIP_GATEWAY:设为 "1" or "true" 临时恢复旧 Next 3000 入口。
|
||||
* - MNOTE_WEB_ENABLE_LEGACY_NEXT_COMPAT:设为 "1" or "true" 时才启动 Next legacy upstream。
|
||||
* - MNOTE_WEB_ENABLE_LEGACY_NEXT_COMPAT:已废弃;desktop:hot 默认不再启动 Next legacy upstream。
|
||||
* - NEXT_LEGACY_PORT:显式启用 legacy compat 时的 Next upstream 端口,默认 3100。
|
||||
* - SKIP_NEXT_LEGACY:兼容旧环境变量;设为 "1" or "true" 时强制只启动 Rust gateway。
|
||||
*/
|
||||
@@ -72,19 +74,21 @@ function shouldStartCelery(env = process.env) {
|
||||
return isEnabledEnv(env.ENABLE_CELERY);
|
||||
}
|
||||
|
||||
function shouldStartBackend(env = process.env) {
|
||||
if (isEnabledEnv(env.SKIP_BACKEND)) return false;
|
||||
if (String(env.BACKEND_CMD || "").trim()) return true;
|
||||
return isEnabledEnv(env.ENABLE_BACKEND);
|
||||
}
|
||||
|
||||
function resolveRuntimePlan(env = process.env) {
|
||||
const frontendPort = Number(env.FRONTEND_PORT || 3000);
|
||||
const nextLegacyPort = Number(env.NEXT_LEGACY_PORT || 3100);
|
||||
const skipGateway = isEnabledEnv(env.MNOTE_WEB_SKIP_GATEWAY);
|
||||
const legacyCompatRequested =
|
||||
!skipGateway &&
|
||||
isEnabledEnv(env.MNOTE_WEB_ENABLE_LEGACY_NEXT_COMPAT) &&
|
||||
!isEnabledEnv(env.SKIP_NEXT_LEGACY);
|
||||
const skipNextLegacy = !skipGateway && !legacyCompatRequested;
|
||||
const skipNextLegacy = !skipGateway;
|
||||
const publicPort = Number.isFinite(frontendPort) ? Math.floor(frontendPort) : 3000;
|
||||
const legacyPort = Number.isFinite(nextLegacyPort) ? Math.floor(nextLegacyPort) : 3100;
|
||||
const legacyUrl = `http://127.0.0.1:${legacyPort}`;
|
||||
const legacyCompatEnabled = legacyCompatRequested ? "1" : "0";
|
||||
const legacyCompatEnabled = "0";
|
||||
|
||||
return {
|
||||
skipGateway,
|
||||
@@ -93,17 +97,14 @@ function resolveRuntimePlan(env = process.env) {
|
||||
legacyPort,
|
||||
publicUrl: `http://localhost:${publicPort}`,
|
||||
legacyUrl,
|
||||
frontendTaskName: skipGateway ? "frontend" : skipNextLegacy ? null : "next-legacy",
|
||||
frontendTaskName: skipGateway ? "frontend" : null,
|
||||
frontendCommand: env.FRONTEND_CMD || `pnpm dev -p ${skipGateway ? publicPort : legacyPort}`,
|
||||
mnoteWebCommand: env.MNOTE_WEB_CMD || "cargo run -p mnote-web --bin mnote-web",
|
||||
mnoteWebEnv: skipGateway
|
||||
? {}
|
||||
: {
|
||||
MNOTE_WEB_BIND: env.MNOTE_WEB_BIND || `127.0.0.1:${publicPort}`,
|
||||
MNOTE_WEB_BIND: env.MNOTE_WEB_BIND || `0.0.0.0:${publicPort}`,
|
||||
MNOTE_WEB_PUBLIC_BIND: env.MNOTE_WEB_PUBLIC_BIND || `127.0.0.1:${publicPort}`,
|
||||
...(skipNextLegacy
|
||||
? {}
|
||||
: { MNOTE_WEB_LEGACY_NEXT_BASE_URL: env.MNOTE_WEB_LEGACY_NEXT_BASE_URL || legacyUrl }),
|
||||
MNOTE_WEB_ENABLE_LEGACY_NEXT_COMPAT: legacyCompatEnabled,
|
||||
},
|
||||
};
|
||||
@@ -135,13 +136,17 @@ const tasks = [
|
||||
cwd: path.join(rootDir, "rust"),
|
||||
},
|
||||
]),
|
||||
{
|
||||
name: "backend",
|
||||
command:
|
||||
process.env.BACKEND_CMD ||
|
||||
`${pythonBin} -m uvicorn app.main:app --reload --port 8000`,
|
||||
cwd: backendDir,
|
||||
},
|
||||
...(shouldStartBackend(process.env)
|
||||
? [
|
||||
{
|
||||
name: "backend",
|
||||
command:
|
||||
process.env.BACKEND_CMD ||
|
||||
`${pythonBin} -m uvicorn app.main:app --reload --port 8000`,
|
||||
cwd: backendDir,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
||||
function findTask(name) {
|
||||
@@ -549,7 +554,7 @@ async function main() {
|
||||
if (runtimePlan.frontendTaskName === "next-legacy") {
|
||||
logPrefix("next-legacy", `Next legacy upstream:${runtimePlan.legacyUrl}`);
|
||||
} else {
|
||||
logPrefix("next-legacy", "默认不启动历史 Next upstream;如需临时兼容请设置 MNOTE_WEB_ENABLE_LEGACY_NEXT_COMPAT=1。");
|
||||
logPrefix("next-legacy", "desktop:hot 默认不启动历史 Next upstream,3000 由 Rust mnote-web 独占。");
|
||||
}
|
||||
const gatewayTask = tasks.find((task) => task.name === "mnote-web");
|
||||
if (gatewayTask) {
|
||||
@@ -559,7 +564,7 @@ async function main() {
|
||||
}
|
||||
|
||||
const desiredBackendPort = backendPortFromEnv;
|
||||
if (!process.env.BACKEND_CMD) {
|
||||
if (shouldStartBackend(process.env) && !process.env.BACKEND_CMD) {
|
||||
const backendPortOk = await ensurePortFree(desiredBackendPort, "backend");
|
||||
if (!backendPortOk) {
|
||||
console.error(`后端端口 ${desiredBackendPort} 无法释放,已中止启动。`);
|
||||
@@ -570,6 +575,10 @@ async function main() {
|
||||
throw new Error("缺少后端任务配置");
|
||||
}
|
||||
backendTask.command = `${pythonBin} -m uvicorn app.main:app --reload --port ${desiredBackendPort}`;
|
||||
} else if (isEnabledEnv(process.env.SKIP_BACKEND)) {
|
||||
logPrefix("backend", "已跳过 FastAPI 后端(SKIP_BACKEND=1)。");
|
||||
} else if (!shouldStartBackend(process.env)) {
|
||||
logPrefix("backend", "默认不启动 FastAPI 后端;desktop:hot 保持 3000 单入口。如需启用请设置 ENABLE_BACKEND=1 或 BACKEND_CMD。");
|
||||
}
|
||||
|
||||
if (shouldStartCelery(process.env)) {
|
||||
@@ -625,6 +634,7 @@ module.exports = {
|
||||
isPortFree,
|
||||
resolveRuntimePlan,
|
||||
resolveBackendExecutable,
|
||||
shouldStartBackend,
|
||||
shouldStartCelery,
|
||||
terminatePid,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user