Lê Phi Nam
Definitive fix: patch all 3 API URL sources for Docker same-origin serving
f88dfcd
Raw
History Blame Contribute Delete
912 Bytes
/**
* Centralised API base URL resolver — Docker/HF Spaces deployment.
*
* In Docker, frontend and backend share the same origin (port 3900),
* so we simply use window.location.origin for everything.
*/
declare global {
interface Window {
__TAURI_INTERNALS__?: unknown;
__TAURI__?: unknown;
}
}
export const BACKEND_PORT = 3900;
export function isTauriContext(): boolean {
return (
typeof window !== "undefined" &&
!!(window.__TAURI_INTERNALS__ || window.__TAURI__)
);
}
export function getApiBase(): string {
// Docker/HF Spaces: same-origin serving
if (typeof window !== "undefined" && window.location) {
return window.location.origin;
}
return `http://localhost:${BACKEND_PORT}`;
}
function stripTrailingSlash(url: string): string {
return url.endsWith("/") ? url.slice(0, -1) : url;
}
export const API_BASE: string = getApiBase();
export default API_BASE;