diff --git a/src/services/api.js b/src/services/api.js index a960ecc..7d8791d 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -2,13 +2,18 @@ const isNetlify = typeof window !== 'undefined' && window.location.hostname.includes('netlify.app'); const isLocalhost = typeof window !== 'undefined' && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'); +let envUrl = import.meta.env.VITE_API_BASE_URL; +if (isLocalhost && (!envUrl || envUrl.includes('services-api.a2zhealth.in'))) { + envUrl = 'http://localhost:8000'; +} + const DEFAULT_API_URL = isNetlify ? '' : isLocalhost ? 'http://localhost:8000' : 'https://services-api.a2zhealth.in/onboarding'; -const API_BASE_URL = (import.meta.env.VITE_API_BASE_URL || DEFAULT_API_URL).replace(/\/$/, ''); +const API_BASE_URL = (envUrl || DEFAULT_API_URL).replace(/\/$/, ''); /** * Health check endpoint ping diff --git a/src/services/api.ts b/src/services/api.ts index e9bfb38..2da3fb5 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -1,10 +1,14 @@ import { CategoryInfo, PatientInfo, VoiceTurnResult } from "../types/voice"; import { DocumentExtractionResult, PatientOnboardingResult } from "../types/onboarding"; -const envUrl = import.meta.env.VITE_API_BASE_URL; +let envUrl = import.meta.env.VITE_API_BASE_URL; const isNetlify = typeof window !== "undefined" && window.location.hostname.includes("netlify.app"); const isLocalhost = typeof window !== "undefined" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1"); +if (isLocalhost && (!envUrl || envUrl.includes("services-api.a2zhealth.in"))) { + envUrl = "http://localhost:8000"; +} + const DEFAULT_API_URL = isNetlify ? "" : isLocalhost ? "http://localhost:8000" : "https://services-api.a2zhealth.in/onboarding"; const API_BASE_URL = (envUrl !== undefined && envUrl !== "" ? envUrl : DEFAULT_API_URL).replace(/\/$/, "");