Farhan Beg commited on
Commit ·
cb6f955
1
Parent(s): eecc3ba
revert: remove Android app /api/sessions route + Origin strip
Browse filesReverts commits b0371e0, 060f85e, eecc3ba — the Android app
compatibility changes that broke the WebUI login loop and didn't
fix the Android app anyway.
Removed:
- /api/sessions gateway route (conflicted with WebUI's own /api/sessions)
- Origin header strip for gateway proxy (was for gateway CORS 403)
health-server.js is back to the state from bf86338 (db-wal fix).
- health-server.js +1 -41
health-server.js
CHANGED
|
@@ -406,14 +406,7 @@ function proxyRequest(
|
|
| 406 |
...req.headers,
|
| 407 |
...headerOverrides,
|
| 408 |
host: `${GATEWAY_HOST}:${targetPort}`,
|
| 409 |
-
|
| 410 |
-
// rejects mismatches, so we rewrite Origin to the local backend. But the
|
| 411 |
-
// gateway (port 8642) has a CORS middleware that returns 403 for ANY
|
| 412 |
-
// non-empty Origin when API_SERVER_CORS_ORIGINS is not configured. Since
|
| 413 |
-
// the router is a reverse proxy (not a browser making a CORS request),
|
| 414 |
-
// strip Origin for gateway calls so the gateway treats it as a non-browser
|
| 415 |
-
// client and allows it. headerOverrides can re-add it if needed.
|
| 416 |
-
origin: targetPort === GATEWAY_PORT ? "" : localOrigin,
|
| 417 |
"x-forwarded-host": req.headers.host || "",
|
| 418 |
"x-forwarded-proto": req.headers["x-forwarded-proto"] || "https",
|
| 419 |
};
|
|
@@ -1106,39 +1099,6 @@ const server = http.createServer(async (req, res) => {
|
|
| 1106 |
return;
|
| 1107 |
}
|
| 1108 |
|
| 1109 |
-
// 5b. /api/sessions and /api/sessions/* — Hermes gateway session API.
|
| 1110 |
-
// The Android app (rusty4444/hermes-android) and other OpenAI-compatible
|
| 1111 |
-
// clients call these directly on the gateway (port 8642) with a Bearer
|
| 1112 |
-
// token. The WebUI (nesquena/hermes-webui) ALSO calls /api/sessions but
|
| 1113 |
-
// uses cookie auth (no Bearer). To avoid intercepting the WebUI's own
|
| 1114 |
-
// session calls (which caused a login loop), only route to the gateway
|
| 1115 |
-
// when the request carries a Bearer token. Requests without Bearer fall
|
| 1116 |
-
// through to the WebUI catch-all as before.
|
| 1117 |
-
if (
|
| 1118 |
-
(path === "/api/sessions" || path.startsWith("/api/sessions/")) &&
|
| 1119 |
-
getBearerToken(req)
|
| 1120 |
-
) {
|
| 1121 |
-
if (!isAuthorized(req)) {
|
| 1122 |
-
res.writeHead(401, {
|
| 1123 |
-
"content-type": "application/json",
|
| 1124 |
-
"cache-control": "no-store",
|
| 1125 |
-
});
|
| 1126 |
-
res.end(
|
| 1127 |
-
JSON.stringify({
|
| 1128 |
-
error: "unauthorized",
|
| 1129 |
-
message: "Use Authorization: Bearer <GATEWAY_TOKEN>.",
|
| 1130 |
-
}),
|
| 1131 |
-
);
|
| 1132 |
-
return;
|
| 1133 |
-
}
|
| 1134 |
-
const upstreamHeaders =
|
| 1135 |
-
getBearerToken(req) || !API_SERVER_KEY
|
| 1136 |
-
? {}
|
| 1137 |
-
: { authorization: `Bearer ${API_SERVER_KEY}` };
|
| 1138 |
-
proxyRequest(req, res, GATEWAY_PORT, (p) => p, upstreamHeaders);
|
| 1139 |
-
return;
|
| 1140 |
-
}
|
| 1141 |
-
|
| 1142 |
// 6. /hm — HuggingMes status page.
|
| 1143 |
if (path === HM_PREFIX || path === `${HM_PREFIX}/`) {
|
| 1144 |
if (!requireAuth(req, res)) return;
|
|
|
|
| 406 |
...req.headers,
|
| 407 |
...headerOverrides,
|
| 408 |
host: `${GATEWAY_HOST}:${targetPort}`,
|
| 409 |
+
origin: localOrigin,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
"x-forwarded-host": req.headers.host || "",
|
| 411 |
"x-forwarded-proto": req.headers["x-forwarded-proto"] || "https",
|
| 412 |
};
|
|
|
|
| 1099 |
return;
|
| 1100 |
}
|
| 1101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1102 |
// 6. /hm — HuggingMes status page.
|
| 1103 |
if (path === HM_PREFIX || path === `${HM_PREFIX}/`) {
|
| 1104 |
if (!requireAuth(req, res)) return;
|