Files
OmniRoute/src/shared/utils/wsPath.ts
Septianata Rizky Pratama 45310f202d fix: auto-start WS server in-process and change default port to 20132 (#6072)
* feat: change default LIVE_WS_PORT from 20129 to 20132

Update the default WebSocket port for the live dashboard server from 20129 to 20132 across all configuration files, documentation, code comments, and tests. Also consolidate OMNIROUTE_DISABLE_LIVE_WS and OMNIROUTE_ENABLE_LIVE_WS into a single OMNIROUTE_ENABLE_LIVE_WS flag. Wire the live WebSocket server to start in-process via instrumentation-node.ts.

* feat: clarify NEXT_PUBLIC_LIVE_WS_PUBLIC_URL path usage and derive upgrade path from URL

Update .env.example and ENVIRONMENT.md to document that the pathname portion of NEXT_PUBLIC_LIVE_WS_PUBLIC_URL (e.g. /live-ws) is used as the WebSocket upgrade path by the dev proxy, handshake response, and client connection logic.

Extract deriveLiveWsPath() into shared/utils/wsPath.ts and wire it through:
- src/app/api/v1/ws/route.ts — handshake response path field
- src/hooks/useLiveDashboard.ts — build

* fix: use the standard URL API to safely parse and update the effectiveWsUrl

* build(docker): expose live WebSocket server port and configure CORS origins

Add LIVE_WS_PORT (20132), LIVE_WS_HOST (0.0.0.0), and LIVE_WS_ALLOWED_ORIGINS environment variables to all Docker Compose profiles and expose the WebSocket port mapping. Prevent infinite self-loop in standalone-server-ws.mjs by skipping proxy when the server itself is running on the LiveWS port.

* docs(env): fix comment formatting for HOST and HOSTNAME variables

---------

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-11 01:01:27 -03:00

30 lines
1.1 KiB
TypeScript

/**
* Derive the live WebSocket path from `NEXT_PUBLIC_LIVE_WS_PUBLIC_URL`.
*
* Only `ws://` or `wss://` URLs are accepted (mirrors the scheme guard in
* `getLivePublicUrl()`). The pathname is extracted and used as the WS upgrade
* path; if the URL has no pathname (or is `/`), falls back to `/live-ws`.
*
* Used by:
* - `src/app/api/v1/ws/route.ts` — handshake response `path` field
* - `src/hooks/useLiveDashboard.ts` — build-time path constant + runtime discovery
*
* No env var is introduced — this reads the existing `NEXT_PUBLIC_LIVE_WS_PUBLIC_URL`.
*/
export function deriveLiveWsPath(publicUrl?: string): string {
if (!publicUrl) return "/live-ws";
if (!publicUrl.startsWith("ws://") && !publicUrl.startsWith("wss://")) return "/live-ws";
try {
const parsed = new URL(publicUrl);
const pathname = parsed.pathname;
return pathname && pathname !== "/" ? pathname : "/live-ws";
} catch {
return "/live-ws";
}
}
/** Convenience: read the env var at call time and derive the path. */
export function getLiveWsPath(): string {
return deriveLiveWsPath(process.env.NEXT_PUBLIC_LIVE_WS_PUBLIC_URL);
}