devsite/app/utils/getApiUrl.ts
2025-02-09 15:43:50 +01:00

19 lines
880 B
TypeScript

export function getApiUrl() {
if (typeof window !== "undefined") {
// 🔥 Détection du mode local côté client
const isLocalhost =
window.location.hostname === "localhost" ||
window.location.hostname === "127.0.0.1" ||
window.location.hostname.startsWith("192.168.") ||
window.location.hostname.endsWith(".local");
console.log("🌍 [getApiUrl] Mode CLIENT détecté - URL :", isLocalhost ? "http://localhost:1337" : "https://api.fernandgrascalvet.com");
return isLocalhost ? "http://localhost:1337" : "https://api.fernandgrascalvet.com";
}
// 🔥 Côté serveur (SSR), on utilise une variable d'environnement
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "https://api.fernandgrascalvet.com";
console.log("🌍 [getApiUrl] Mode SERVEUR détecté - URL :", apiUrl);
return apiUrl;
}