Spaces:
Running
Running
Download frontend/src/utils/api.js from Agmmm/valhalla: direct link, hf CLI and curl.
- Browser
- Download file 671 Bytes
-
https://huggingface.co/spaces/Agmmm/valhalla/resolve/main/frontend/src/utils/api.js
- Command line
-
hf download hf://spaces/Agmmm/valhalla/frontend/src/utils/api.js
-
curl -L -o api.js https://huggingface.co/spaces/Agmmm/valhalla/resolve/main/frontend/src/utils/api.js
671 Bytes
| /** | |
| * 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}`; | |
| } | |