// ── Chemin de base (reverse proxy en sous-dossier) ───────────── // Injecté par le serveur dans index.html (cf. server/index.ts) : l'application // suit le préfixe du reverse proxy sans rebuild. Vide en développement, où Vite // sert l'application à la racine. declare global { interface Window { __BASE_URL__?: string } } export const BASE_URL: string = window.__BASE_URL__ ?? '' // Préfixe un chemin absolu de l'application ('/api/...', '/invite/...') export function withBase(path: string): string { return path.startsWith('/') ? `${BASE_URL}${path}` : path } // URL absolue affichable (lien d'invitation, adresse de l'API publique) export function absoluteUrl(path: string): string { return `${window.location.origin}${withBase(path)}` } // Les quelque 140 appels `fetch('/api/…')` du code applicatif sont préfixés ici // plutôt qu'un par un : un seul endroit à maintenir, et les nouveaux appels en // bénéficient automatiquement. Les URL absolues (api.github.com, clients // torrent distants) et les chemins ne visant pas l'API ne sont pas touchés. export function installFetchBasePrefix(): void { if (!BASE_URL) return const nativeFetch = window.fetch.bind(window) window.fetch = (input: RequestInfo | URL, init?: RequestInit) => { if (typeof input === 'string' && input.startsWith('/api/')) { return nativeFetch(BASE_URL + input, init) } return nativeFetch(input, init) } }