From cc715e24b24455a509892ff5391c52dd2d2047a1 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Fri, 11 Sep 2026 12:39:50 +0000 Subject: [PATCH] Fix the feedback URL and stop serving a UI when WEB_STATIC=0 VITE_GATEWAY_URL names a WebSocket origin, and FEEDBACK_URL was derived from it verbatim - so with VITE_GATEWAY_URL=wss://gateway.example the form posted to wss://gateway.example/api/feedback, which fetch() refuses outright ("TypeError: unknown scheme"). Every submission from a separately hosted frontend failed before it left the browser. Map the scheme back to http(s); an already-http VITE_GATEWAY_URL is untouched. While there: WEB_STATIC=0 answered every path with the dev hint page, which talks about localhost:5173 and npm run dev. That page is wrong for a gateway that is reachable publicly, and an SPA-shaped answer on every path makes the host look like a second, stale copy of the app. Serve a short deployment-neutral notice at "/" and 404 everywhere else; the dev hint stays for the case it is actually about, a missing web/dist. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- gateway/src/index.ts | 25 +++++++++++++++++++++++-- web/src/App.tsx | 7 +++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/gateway/src/index.ts b/gateway/src/index.ts index f648041..3f06355 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -245,12 +245,25 @@ async function handleFeedback(req: IncomingMessage, res: ServerResponse) { const DEV_HINT = `

WebSpeak3 gateway

WebSocket: /ws

-

Static UI is disabled (WEB_STATIC=0) or web/dist is missing.

+

web/dist is missing — the UI has not been built yet.

For local development open the Vite app at http://localhost:5173/ (run npm run dev in web/). Rebuild with npm run build in web/ to serve the UI from this port again.

`; +/** + * 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 = ` +WebSpeak3 gateway + +

WebSpeak3 gateway

+

WebSocket endpoint: /ws

+

No web UI is served from this host.

+`; + /** * TLS material, when configured. * @@ -280,8 +293,16 @@ const requestHandler = (req: IncomingMessage, res: ServerResponse) => { } 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(DEV_HINT); + res.end(NO_UI_NOTICE); return; } let filePath = path.join(WEB_DIST, decodeURIComponent(requestUrl.pathname)); diff --git a/web/src/App.tsx b/web/src/App.tsx index 2a2f77d..c808954 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -86,11 +86,14 @@ const GATEWAY_URL = import.meta.env.DEV // Same derivation as GATEWAY_URL above, but for a plain HTTP POST (the // feedback form) instead of the WebSocket - see gateway/src/index.ts's -// /api/feedback handler. +// /api/feedback handler. VITE_GATEWAY_URL names a WebSocket origin, so its +// scheme has to be mapped back to http(s) here: fetch() refuses anything +// else outright ("TypeError: unknown scheme"), so with VITE_GATEWAY_URL set +// the form could not submit at all. const FEEDBACK_URL = import.meta.env.DEV ? "http://localhost:8080/api/feedback" : import.meta.env.VITE_GATEWAY_URL - ? `${import.meta.env.VITE_GATEWAY_URL.replace(/\/$/, "")}/api/feedback` + ? `${import.meta.env.VITE_GATEWAY_URL.replace(/\/$/, "").replace(/^ws(s?):\/\//, "http$1://")}/api/feedback` : `${window.location.protocol}//${window.location.host}/api/feedback`; // This file's frontend is deployed as multiple Cloudflare Pages projects