Override .env VITE_API_BASE_URL when on localhost to point to local backend http://localhost:8000
This commit is contained in:
+6
-1
@@ -2,13 +2,18 @@
|
|||||||
const isNetlify = typeof window !== 'undefined' && window.location.hostname.includes('netlify.app');
|
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');
|
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
|
const DEFAULT_API_URL = isNetlify
|
||||||
? ''
|
? ''
|
||||||
: isLocalhost
|
: isLocalhost
|
||||||
? 'http://localhost:8000'
|
? 'http://localhost:8000'
|
||||||
: 'https://services-api.a2zhealth.in/onboarding';
|
: '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
|
* Health check endpoint ping
|
||||||
|
|||||||
+5
-1
@@ -1,10 +1,14 @@
|
|||||||
import { CategoryInfo, PatientInfo, VoiceTurnResult } from "../types/voice";
|
import { CategoryInfo, PatientInfo, VoiceTurnResult } from "../types/voice";
|
||||||
import { DocumentExtractionResult, PatientOnboardingResult } from "../types/onboarding";
|
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 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");
|
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 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(/\/$/, "");
|
const API_BASE_URL = (envUrl !== undefined && envUrl !== "" ? envUrl : DEFAULT_API_URL).replace(/\/$/, "");
|
||||||
|
|||||||
Reference in New Issue
Block a user