mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 09:58:38 +00:00
Revert "fix: respect OPENCLAW_HOME for isolated gateway instances"
This reverts commit 34b18ea9db.
This commit is contained in:
@@ -3,7 +3,7 @@ import path from "node:path";
|
|||||||
import type { Command } from "commander";
|
import type { Command } from "commander";
|
||||||
import type { GatewayAuthMode } from "../../config/config.js";
|
import type { GatewayAuthMode } from "../../config/config.js";
|
||||||
import {
|
import {
|
||||||
getConfigPath,
|
CONFIG_PATH,
|
||||||
loadConfig,
|
loadConfig,
|
||||||
readConfigFileSnapshot,
|
readConfigFileSnapshot,
|
||||||
resolveStateDir,
|
resolveStateDir,
|
||||||
@@ -161,7 +161,7 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
|
|||||||
const tokenRaw = toOptionString(opts.token);
|
const tokenRaw = toOptionString(opts.token);
|
||||||
|
|
||||||
const snapshot = await readConfigFileSnapshot().catch(() => null);
|
const snapshot = await readConfigFileSnapshot().catch(() => null);
|
||||||
const configExists = snapshot?.exists ?? fs.existsSync(getConfigPath());
|
const configExists = snapshot?.exists ?? fs.existsSync(CONFIG_PATH);
|
||||||
const configAuditPath = path.join(resolveStateDir(process.env), "logs", "config-audit.jsonl");
|
const configAuditPath = path.join(resolveStateDir(process.env), "logs", "config-audit.jsonl");
|
||||||
const mode = cfg.gateway?.mode;
|
const mode = cfg.gateway?.mode;
|
||||||
if (!opts.allowUnconfigured && mode !== "local") {
|
if (!opts.allowUnconfigured && mode !== "local") {
|
||||||
|
|||||||
@@ -182,21 +182,8 @@ export function resolveConfigPath(
|
|||||||
return path.join(stateDir, CONFIG_FILENAME);
|
return path.join(stateDir, CONFIG_FILENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use resolveConfigPathCandidate() instead. This constant is evaluated
|
|
||||||
* at module load time and does not respect OPENCLAW_HOME set after import.
|
|
||||||
* Kept for backwards compatibility but should be avoided in new code.
|
|
||||||
*/
|
|
||||||
export const CONFIG_PATH = resolveConfigPathCandidate();
|
export const CONFIG_PATH = resolveConfigPathCandidate();
|
||||||
|
|
||||||
/**
|
|
||||||
* Runtime-evaluated config path that respects OPENCLAW_HOME.
|
|
||||||
* Use this instead of CONFIG_PATH when OPENCLAW_HOME may be set dynamically.
|
|
||||||
*/
|
|
||||||
export function getConfigPath(env: NodeJS.ProcessEnv = process.env): string {
|
|
||||||
return resolveConfigPathCandidate(env, envHomedir(env));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve default config path candidates across default locations.
|
* Resolve default config path candidates across default locations.
|
||||||
* Order: explicit config path → state-dir-derived paths → new default.
|
* Order: explicit config path → state-dir-derived paths → new default.
|
||||||
@@ -271,22 +258,6 @@ export function resolveGatewayPort(
|
|||||||
cfg?: OpenClawConfig,
|
cfg?: OpenClawConfig,
|
||||||
env: NodeJS.ProcessEnv = process.env,
|
env: NodeJS.ProcessEnv = process.env,
|
||||||
): number {
|
): number {
|
||||||
// When OPENCLAW_HOME is set (isolated instance), prefer config over inherited env vars.
|
|
||||||
// This prevents a parent gateway's OPENCLAW_GATEWAY_PORT from bleeding through.
|
|
||||||
const isIsolatedInstance = Boolean(env.OPENCLAW_HOME?.trim());
|
|
||||||
|
|
||||||
// Config port takes precedence for isolated instances
|
|
||||||
const configPort = cfg?.gateway?.port;
|
|
||||||
if (
|
|
||||||
isIsolatedInstance &&
|
|
||||||
typeof configPort === "number" &&
|
|
||||||
Number.isFinite(configPort) &&
|
|
||||||
configPort > 0
|
|
||||||
) {
|
|
||||||
return configPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check env vars (for non-isolated or when config doesn't specify port)
|
|
||||||
const envRaw = env.OPENCLAW_GATEWAY_PORT?.trim() || env.CLAWDBOT_GATEWAY_PORT?.trim();
|
const envRaw = env.OPENCLAW_GATEWAY_PORT?.trim() || env.CLAWDBOT_GATEWAY_PORT?.trim();
|
||||||
if (envRaw) {
|
if (envRaw) {
|
||||||
const parsed = Number.parseInt(envRaw, 10);
|
const parsed = Number.parseInt(envRaw, 10);
|
||||||
@@ -294,11 +265,11 @@ export function resolveGatewayPort(
|
|||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const configPort = cfg?.gateway?.port;
|
||||||
// Fall back to config for non-isolated instances
|
if (typeof configPort === "number" && Number.isFinite(configPort)) {
|
||||||
if (typeof configPort === "number" && Number.isFinite(configPort) && configPort > 0) {
|
if (configPort > 0) {
|
||||||
return configPort;
|
return configPort;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DEFAULT_GATEWAY_PORT;
|
return DEFAULT_GATEWAY_PORT;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user