MetiMiester's picture
Update frontend/src/lib/api.ts
a77382d verified
raw
history blame contribute delete
743 Bytes
// frontend/src/lib/api.ts
import axios from "axios";
/**
* Compute API base. On HF Spaces we want same-origin (no host at all).
* Locally (vite dev) you can set VITE_API_BASE=http://localhost:4000
* but if it's empty we default to same-origin.
*/
const envBase = (import.meta.env.VITE_API_BASE ?? "").trim();
export const API_BASE =
envBase !== "" ? envBase.replace(/\/$/, "") : ""; // "" = same origin
export const api = axios.create({
baseURL: `${API_BASE}/api`,
withCredentials: false,
headers: { "Content-Type": "application/json" },
});
// Optional helper
export async function health(): Promise<{ ok: boolean; db: string }> {
const res = await fetch(`${API_BASE}/health`, { cache: "no-store" });
return res.json();
}