Spaces:
Running
Running
| /** | |
| * Centralized API configuration. | |
| * This setup allows the client to communicate with a backend server on a different domain, | |
| * which is necessary for the planned Hugging Face Space architecture where the client and server | |
| * are in separate spaces. | |
| */ | |
| // Use VITE_API_SERVER_URL from the .env file to specify the backend server URL. | |
| // For local development, this can point to the local Python server (e.g., "http://127.0.0.1:8000"). | |
| // For production, this will be the URL of your private Hugging Face Space (e.g., "https://your-private-space.hf.space"). | |
| const API_BASE_URL = import.meta.env.VITE_API_SERVER_URL || ""; | |
| /** | |
| * Constructs a full URL for an API endpoint or a server-hosted resource. | |
| * If VITE_API_SERVER_URL is set, it prepends it to the path. | |
| * Otherwise, it returns the path as-is, assuming a same-origin request (useful for proxies). | |
| * @param {string} path - The relative path of the API endpoint (e.g., '/api/upload' or '/data/converted/.../tileset.json'). | |
| * @returns {string} The full URL. | |
| */ | |
| export function getApiUrl(path) { | |
| // If the path is already a full URL, return it directly. | |
| if (path.startsWith("http://") || path.startsWith("https://")) { | |
| return path; | |
| } | |
| const formattedPath = path.startsWith("/") ? path : `/${path}`; | |
| return `${API_BASE_URL}${formattedPath}`; | |
| } | |
| /** | |
| * A wrapper for the native fetch function. This is a convenient place to inject | |
| * authentication headers or perform other request modifications in the future. | |
| * @param {string} url - The URL to fetch. | |
| * @param {object} options - The options for the fetch call. | |
| * @returns {Promise<Response>} The fetch promise. | |
| */ | |
| export function fetchWithAuth(url, options) { | |
| // Future logic for adding auth tokens can go here. | |
| return fetch(url, options); | |
| } |