From fa4daf78315654cf7e276b4131c2203464891659 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Fri, 11 Sep 2026 15:34:16 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- Dockerfile | 2 +- gateway/src/index.ts | 40 +++++++++++++++++----------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 97abf09..da30611 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,6 +60,6 @@ ENV CONNECTOR_BIN=/app/connector-bin/ts-connector EXPOSE 8080 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"] diff --git a/gateway/src/index.ts b/gateway/src/index.ts index cc70bb2..e685c94 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -251,19 +251,6 @@ const DEV_HINT = ` -WebSpeak3 gateway - -

WebSpeak3 gateway

-

WebSocket endpoint: /ws

-

No web UI is served from this host.

-`; - /** * TLS material, when configured. * @@ -292,17 +279,24 @@ const requestHandler = (req: IncomingMessage, res: ServerResponse) => { 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) { - // No SPA fallback here: with the UI hosted elsewhere, answering every - // path with a page would put a second, stale-looking "app" on this - // hostname. Only "/" gets a notice, everything else is simply absent. - if (requestUrl.pathname !== "/") { - res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" }); - res.end("Not found\n"); - return; - } - res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); - res.end(NO_UI_NOTICE); + // With the UI hosted elsewhere this process is an API endpoint and + // nothing else: no SPA fallback, and not even a notice page at "/", + // which would only put a second, stale-looking "app" on a hostname + // that is meant to answer /ws and /api/feedback. Everything a browser + // asks for is simply absent. + res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" }); + res.end("Not found\n"); return; } let filePath = path.join(WEB_DIST, decodeURIComponent(requestUrl.pathname));