Spaces:
Sleeping
Sleeping
tao-shen Claude Opus 4.6 commited on
Commit Β·
9512030
1
Parent(s): f113c31
feat: auto-fill gateway token via URL redirect
Browse filesAdd token-redirect.cjs preload script that redirects "/" to
"/?token=GATEWAY_TOKEN". The Control UI reads token from URL params
and auto-fills it, so users don't need to manually enter the token.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- scripts/entrypoint.sh +3 -0
- scripts/token-redirect.cjs +37 -0
scripts/entrypoint.sh
CHANGED
|
@@ -26,6 +26,9 @@ export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/scripts
|
|
| 26 |
# Enable Telegram API proxy (redirects fetch() to working mirror if needed)
|
| 27 |
export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/scripts/telegram-proxy.cjs"
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
# ββ Extensions symlink ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
SYMLINK_START=$(date +%s)
|
| 31 |
if [ ! -L /home/node/.openclaw/extensions ]; then
|
|
|
|
| 26 |
# Enable Telegram API proxy (redirects fetch() to working mirror if needed)
|
| 27 |
export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/scripts/telegram-proxy.cjs"
|
| 28 |
|
| 29 |
+
# Auto-fill gateway token in Control UI (redirects "/" to "/?token=GATEWAY_TOKEN")
|
| 30 |
+
export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/scripts/token-redirect.cjs"
|
| 31 |
+
|
| 32 |
# ββ Extensions symlink ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 33 |
SYMLINK_START=$(date +%s)
|
| 34 |
if [ ! -L /home/node/.openclaw/extensions ]; then
|
scripts/token-redirect.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* token-redirect.cjs β Node.js preload script
|
| 3 |
+
*
|
| 4 |
+
* Intercepts HTTP requests to the root URL "/" and redirects to
|
| 5 |
+
* "/?token=GATEWAY_TOKEN" so the Control UI auto-fills the gateway token.
|
| 6 |
+
*
|
| 7 |
+
* Loaded via NODE_OPTIONS --require before OpenClaw starts.
|
| 8 |
+
*/
|
| 9 |
+
'use strict';
|
| 10 |
+
|
| 11 |
+
const http = require('http');
|
| 12 |
+
|
| 13 |
+
const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || 'huggingclaw';
|
| 14 |
+
const origEmit = http.Server.prototype.emit;
|
| 15 |
+
|
| 16 |
+
http.Server.prototype.emit = function (event, ...args) {
|
| 17 |
+
if (event === 'request') {
|
| 18 |
+
const [req, res] = args;
|
| 19 |
+
// Only redirect normal GET to "/" without token β skip WebSocket upgrades
|
| 20 |
+
if (req.method === 'GET' && !req.headers.upgrade) {
|
| 21 |
+
try {
|
| 22 |
+
const url = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
|
| 23 |
+
if (url.pathname === '/' && !url.searchParams.has('token')) {
|
| 24 |
+
url.searchParams.set('token', GATEWAY_TOKEN);
|
| 25 |
+
res.writeHead(302, { Location: url.pathname + url.search });
|
| 26 |
+
res.end();
|
| 27 |
+
return true;
|
| 28 |
+
}
|
| 29 |
+
} catch (_) {
|
| 30 |
+
// URL parse error β pass through
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
return origEmit.apply(this, [event, ...args]);
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
console.log('[token-redirect] Gateway token redirect active');
|