Spaces:
Sleeping
Sleeping
fix: restore 302 redirect for token so frontend JS can read it from URL
Browse filesServer-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>
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:
|
|
|
|
| 234 |
if (req.method === 'GET' && !req.headers.upgrade) {
|
| 235 |
if (pathname === '/' && !parsed.query.token) {
|
| 236 |
-
|
| 237 |
-
|
|
|
|
| 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 |
}
|