File size: 912 Bytes
94004a2
f88dfcd
94004a2
f88dfcd
 
94004a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f88dfcd
94004a2
f88dfcd
94004a2
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * 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;