Revert "fix(openclaw): always set gateway.origin when updating claw subdomain"

This reverts commit 69ac075e8c.
This commit is contained in:
stswangzhiping
2026-03-27 14:42:53 +08:00
parent 69ac075e8c
commit 6ad573e272

View File

@@ -419,11 +419,9 @@ class ClawClient {
const raw = readFileSync(configFile, 'utf8'); const raw = readFileSync(configFile, 'utf8');
const config = JSON.parse(raw); const config = JSON.parse(raw);
const newOrigin = `https://${targetId}.claw.cutos.ai`; const newOrigin = `https://${targetId}.claw.cutos.ai`;
const newOriginWss = `wss://${targetId}.claw.cutos.ai`; const re = /https:\/\/[^"'\s]+\.claw\.cutos\.ai/g;
const reHttps = /https:\/\/[^"'\s]+\.claw\.cutos\.ai/g;
const reWss = /wss:\/\/[^"'\s]+\.claw\.cutos\.ai/g;
/** 遍历 JSON 内字符串替换已存在的 claw 子域 URL兼容旧 YAML 全文替换习惯) */ /** 与原 YAML 全文替换等价:遍历 JSON 内所有字符串替换匹配的 origin */
const replaceOriginStrings = (node) => { const replaceOriginStrings = (node) => {
let changed = false; let changed = false;
if (typeof node === 'string') { if (typeof node === 'string') {
@@ -433,7 +431,7 @@ class ClawClient {
for (let i = 0; i < node.length; i++) { for (let i = 0; i < node.length; i++) {
const v = node[i]; const v = node[i];
if (typeof v === 'string') { if (typeof v === 'string') {
const next = v.replace(reHttps, newOrigin).replace(reWss, newOriginWss); const next = v.replace(re, newOrigin);
if (next !== v) { if (next !== v) {
node[i] = next; node[i] = next;
changed = true; changed = true;
@@ -448,7 +446,7 @@ class ClawClient {
for (const k of Object.keys(node)) { for (const k of Object.keys(node)) {
const v = node[k]; const v = node[k];
if (typeof v === 'string') { if (typeof v === 'string') {
const next = v.replace(reHttps, newOrigin).replace(reWss, newOriginWss); const next = v.replace(re, newOrigin);
if (next !== v) { if (next !== v) {
node[k] = next; node[k] = next;
changed = true; changed = true;
@@ -462,18 +460,7 @@ class ClawClient {
return false; return false;
}; };
let changed = replaceOriginStrings(config); if (!replaceOriginStrings(config)) {
// openclaw.json 可能没有旧 URL 可替换(空配置或仅 token必须写入 gateway.origin
if (!config.gateway || typeof config.gateway !== 'object') {
config.gateway = {};
}
if (config.gateway.origin !== newOrigin) {
config.gateway.origin = newOrigin;
changed = true;
}
if (!changed) {
log.info('clawd', `openclaw origin 已是 ${newOrigin},无需变更`); log.info('clawd', `openclaw origin 已是 ${newOrigin},无需变更`);
return; return;
} }