Merge branch 'websocket_context' into staging_environment

This commit is contained in:
Carter 2026-03-20 11:54:40 -06:00
commit 9a06ca8867

16
src/utils/getWsBaseUrl.ts Normal file
View file

@ -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}`;
}