Skip to content

Commit ec47e7c

Browse files
authored
fix(proxy): inject gateway token for proxied http+ws (#146)
1 parent 825962d commit ec47e7c

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Fix:
118118

119119
If `openclaw devices list` shows no pending request IDs:
120120
- Make sure you’re visiting the Control UI at `/openclaw` (or your native app) and letting it attempt to connect
121+
- Note: the Railway wrapper now proxies the gateway and injects the auth token automatically, so you should not need to paste the gateway token into the Control UI when using `/openclaw`.
121122
- Ensure your state dir is the Railway volume (recommended): `OPENCLAW_STATE_DIR=/data/.openclaw`
122123
- Check `/setup/api/debug` for the active state/workspace dirs + gateway readiness
123124

src/server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,16 @@ proxy.on("error", (err, _req, res) => {
13281328
}
13291329
});
13301330

1331+
function attachGatewayAuthHeader(req) {
1332+
// When running behind the Railway wrapper, the gateway is only reachable from this container.
1333+
// The Control UI running in the browser cannot set custom Authorization headers for WebSocket
1334+
// connections, so we terminate auth at the wrapper by injecting the token into proxied
1335+
// requests.
1336+
if (!req?.headers?.authorization && OPENCLAW_GATEWAY_TOKEN) {
1337+
req.headers.authorization = `Bearer ${OPENCLAW_GATEWAY_TOKEN}`;
1338+
}
1339+
}
1340+
13311341
app.use(async (req, res) => {
13321342
// If not configured, force users to /setup for any non-setup routes.
13331343
if (!isConfigured() && !req.path.startsWith("/setup")) {
@@ -1350,6 +1360,7 @@ app.use(async (req, res) => {
13501360
}
13511361
}
13521362

1363+
attachGatewayAuthHeader(req);
13531364
return proxy.web(req, res, { target: GATEWAY_TARGET });
13541365
});
13551366

@@ -1417,6 +1428,7 @@ server.on("upgrade", async (req, socket, head) => {
14171428
socket.destroy();
14181429
return;
14191430
}
1431+
attachGatewayAuthHeader(req);
14201432
proxy.ws(req, socket, head, { target: GATEWAY_TARGET });
14211433
});
14221434

0 commit comments

Comments
 (0)