Merge branch 'websocket_context' into staging_environment
This commit is contained in:
commit
9a06ca8867
1 changed files with 16 additions and 0 deletions
16
src/utils/getWsBaseUrl.ts
Normal file
16
src/utils/getWsBaseUrl.ts
Normal 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}`;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue