From c8cefc828e5b93c5f99a91d2bebcb2ee1fa96090 Mon Sep 17 00:00:00 2001 From: Gokulvarthan Ramesh Date: Sat, 29 Aug 2026 17:47:11 +0530 Subject: [PATCH] Override .env VITE_API_BASE_URL when on localhost to point to local backend http://localhost:8000 --- src/services/api.js | 7 ++++++- src/services/api.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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(/\/$/, "");