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