From f23a5d559dbc8045608593f1a5b02bd71064d91a Mon Sep 17 00:00:00 2001 From: Carter Date: Fri, 20 Mar 2026 11:54:31 -0600 Subject: [PATCH] added forgotten base url file --- src/utils/getWsBaseUrl.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/utils/getWsBaseUrl.ts diff --git a/src/utils/getWsBaseUrl.ts b/src/utils/getWsBaseUrl.ts new file mode 100644 index 0000000..331b78a --- /dev/null +++ b/src/utils/getWsBaseUrl.ts @@ -0,0 +1,16 @@ +/** + * Origin for Pond WebSocket URLs. + * + * VITE_APP_API_URL usually ends with /v1 (same base axios uses for REST). WS paths are + * written as /v1/live/..., so we strip a trailing /v1 from the env URL to avoid /v1/v1/. + */ +export function getWsBaseUrl(): string { + const apiUrl = import.meta.env.VITE_APP_API_URL; + if (apiUrl) { + let ws = apiUrl.replace(/^http/, "ws"); + ws = ws.replace(/\/v1\/?$/, ""); + return ws.replace(/\/$/, "") || ws; + } + const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; + return `${protocol}//${window.location.host}`; +}