From 6ad573e272f685e49cc7c13a93d6455b99c97396 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Fri, 27 Mar 2026 14:42:53 +0800 Subject: [PATCH] Revert "fix(openclaw): always set gateway.origin when updating claw subdomain" This reverts commit 69ac075e8cee6eed094c017c54a605d103320f40. --- lib/client.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/client.js b/lib/client.js index a5d6993..339cb3c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -419,11 +419,9 @@ class ClawClient { const raw = readFileSync(configFile, 'utf8'); const config = JSON.parse(raw); const newOrigin = `https://${targetId}.claw.cutos.ai`; - const newOriginWss = `wss://${targetId}.claw.cutos.ai`; - const reHttps = /https:\/\/[^"'\s]+\.claw\.cutos\.ai/g; - const reWss = /wss:\/\/[^"'\s]+\.claw\.cutos\.ai/g; + const re = /https:\/\/[^"'\s]+\.claw\.cutos\.ai/g; - /** 遍历 JSON 内字符串,替换已存在的 claw 子域 URL(兼容旧 YAML 全文替换习惯) */ + /** 与原 YAML 全文替换等价:遍历 JSON 内所有字符串并替换匹配的 origin */ const replaceOriginStrings = (node) => { let changed = false; if (typeof node === 'string') { @@ -433,7 +431,7 @@ class ClawClient { for (let i = 0; i < node.length; i++) { const v = node[i]; if (typeof v === 'string') { - const next = v.replace(reHttps, newOrigin).replace(reWss, newOriginWss); + const next = v.replace(re, newOrigin); if (next !== v) { node[i] = next; changed = true; @@ -448,7 +446,7 @@ class ClawClient { for (const k of Object.keys(node)) { const v = node[k]; if (typeof v === 'string') { - const next = v.replace(reHttps, newOrigin).replace(reWss, newOriginWss); + const next = v.replace(re, newOrigin); if (next !== v) { node[k] = next; changed = true; @@ -462,18 +460,7 @@ class ClawClient { return false; }; - let changed = 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) { + if (!replaceOriginStrings(config)) { log.info('clawd', `openclaw origin 已是 ${newOrigin},无需变更`); return; }