mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 18:02:49 +08:00
gateway: serve nothing to browsers when WEB_STATIC=0
The notice page at "/" was the last thing a browser could get from a host that only exists to answer /ws and /api/feedback. It is gone; every path now 404s, so the gateway hostname has no web presence at all. That broke the container healthcheck, which probed "/" and required a 200 - a correctly configured gateway would have reported itself unhealthy. The probe now has its own route, /healthz, served before the WEB_STATIC branch so it answers in either mode. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
f48c1cc91a
commit
fa4daf7831
2 files changed
+18
-24
No files matched your search
+1
-1
@@ -60,6 +60,6 @@ ENV CONNECTOR_BIN=/app/connector-bin/ts-connector
|
|||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
CMD ["node", "-e", "fetch('http://127.0.0.1:8080/').then(r => { if (!r.ok) process.exit(1) }).catch(() => process.exit(1))"]
|
CMD ["node", "-e", "fetch('http://127.0.0.1:8080/healthz').then(r => { if (!r.ok) process.exit(1) }).catch(() => process.exit(1))"]
|
||||||
|
|
||||||
CMD ["node", "dist/index.js"]
|
CMD ["node", "dist/index.js"]
|
||||||
+17
-23
@@ -251,19 +251,6 @@ const DEV_HINT = `<!doctype html><html><body style="font:14px system-ui;padding:
|
|||||||
to serve the UI from this port again.</p>
|
to serve the UI from this port again.</p>
|
||||||
</body></html>`;
|
</body></html>`;
|
||||||
|
|
||||||
/**
|
|
||||||
* Shown at "/" when WEB_STATIC=0, i.e. when this process deliberately is not
|
|
||||||
* the app server. Deployment-neutral on purpose: where the UI actually lives
|
|
||||||
* is the operator's business, and this host may well be reachable publicly.
|
|
||||||
*/
|
|
||||||
const NO_UI_NOTICE = `<!doctype html><html lang="en"><head><meta charset="utf-8">
|
|
||||||
<title>WebSpeak3 gateway</title></head>
|
|
||||||
<body style="font:14px system-ui;padding:2rem;max-width:40rem">
|
|
||||||
<h1>WebSpeak3 gateway</h1>
|
|
||||||
<p>WebSocket endpoint: <code>/ws</code></p>
|
|
||||||
<p>No web UI is served from this host.</p>
|
|
||||||
</body></html>`;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TLS material, when configured.
|
* TLS material, when configured.
|
||||||
*
|
*
|
||||||
@@ -292,17 +279,24 @@ const requestHandler = (req: IncomingMessage, res: ServerResponse) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container healthcheck target (see Dockerfile). Deliberately its own
|
||||||
|
// route rather than "/": with WEB_STATIC=0 every browser-facing path
|
||||||
|
// answers 404, and a probe against "/" would then report the process as
|
||||||
|
// unhealthy for doing exactly what it was configured to do.
|
||||||
|
if (requestUrl.pathname === "/healthz") {
|
||||||
|
res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
|
res.end("ok\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SERVE_STATIC) {
|
if (!SERVE_STATIC) {
|
||||||
// No SPA fallback here: with the UI hosted elsewhere, answering every
|
// With the UI hosted elsewhere this process is an API endpoint and
|
||||||
// path with a page would put a second, stale-looking "app" on this
|
// nothing else: no SPA fallback, and not even a notice page at "/",
|
||||||
// hostname. Only "/" gets a notice, everything else is simply absent.
|
// which would only put a second, stale-looking "app" on a hostname
|
||||||
if (requestUrl.pathname !== "/") {
|
// that is meant to answer /ws and /api/feedback. Everything a browser
|
||||||
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
// asks for is simply absent.
|
||||||
res.end("Not found\n");
|
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
return;
|
res.end("Not found\n");
|
||||||
}
|
|
||||||
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
||||||
res.end(NO_UI_NOTICE);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let filePath = path.join(WEB_DIST, decodeURIComponent(requestUrl.pathname));
|
let filePath = path.join(WEB_DIST, decodeURIComponent(requestUrl.pathname));
|
||||||
|
|||||||
Reference in new issue
Block a user