tao-shen Claude Opus 4.6 commited on
Commit
0b2ec75
·
1 Parent(s): 99ce7b7

fix: restore 302 redirect for token so frontend JS can read it from URL

Browse files

Server-side URL rewrite changed req.url internally but the browser
URL stayed as '/' — OpenClaw's frontend JS reads window.location.search
for the token, so it couldn't find it and showed 'offline'. Restored
302 redirect which changes the browser URL to /?token=huggingclaw.
The iframe CSP fix (moved earlier in the code) still applies correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. scripts/token-redirect.cjs +5 -3
scripts/token-redirect.cjs CHANGED
@@ -230,11 +230,13 @@ http.Server.prototype.emit = function (event, ...args) {
230
  return origEmit.apply(this, [event, ...args]);
231
  }
232
  } else {
233
- // Default mode: rewrite URL to inject token (no redirect needed)
 
234
  if (req.method === 'GET' && !req.headers.upgrade) {
235
  if (pathname === '/' && !parsed.query.token) {
236
- req.url = `/?token=${GATEWAY_TOKEN}`;
237
- return origEmit.apply(this, [event, ...args]);
 
238
  }
239
  }
240
  }
 
230
  return origEmit.apply(this, [event, ...args]);
231
  }
232
  } else {
233
+ // Default mode: 302 redirect to inject token into browser URL
234
+ // (must be a redirect, not a rewrite, so frontend JS can read the token)
235
  if (req.method === 'GET' && !req.headers.upgrade) {
236
  if (pathname === '/' && !parsed.query.token) {
237
+ res.writeHead(302, { Location: `/?token=${GATEWAY_TOKEN}` });
238
+ res.end();
239
+ return true;
240
  }
241
  }
242
  }