Spaces:
Running
Running
| /** | |
| * api — URL helpers for REST and WebSocket calls. | |
| * | |
| * apiUrl() prefixes REST paths with the configured VITE_API_URL base; | |
| * wsUrl() converts an http(s) base to the ws(s) scheme for sockets. | |
| * | |
| * Architecture: imported by every component that talks to the backend. | |
| * | |
| * Design: keeps the base URL configuration in one place. | |
| */ | |
| const BASE = import.meta.env.VITE_API_URL || ""; | |
| export function apiUrl(path) { | |
| return `${BASE}${path}`; | |
| } | |
| export function wsUrl(path) { | |
| if (BASE) { | |
| return `${BASE.replace(/^http/, "ws")}${path}`; | |
| } | |
| const protocol = location.protocol === "https:" ? "wss:" : "ws:"; | |
| return `${protocol}//${location.host}${path}`; | |
| } | |