Provide access to change the API base url

This commit is contained in:
Adolfo Reyna
2025-02-22 00:00:59 -05:00
parent ad394a6f18
commit a1b2143337

10
API.js
View File

@@ -1,3 +1,4 @@
const baseUrl = "https://emiapi.reynafamily.com"; const baseUrl = "https://emiapi.reynafamily.com";
//const baseUrl = "http://localhost:3000"; //const baseUrl = "http://localhost:3000";
@@ -6,7 +7,8 @@ let getCall = async (path = "", params = {}) => {
Object.keys(params).forEach(p => { Object.keys(params).forEach(p => {
queryParams += p + "=" + params[p] + "&" queryParams += p + "=" + params[p] + "&"
}); });
return fetch(baseUrl + path + queryParams, { let localBaseUrl = global.baseUrl ?? baseUrl;
return fetch(localBaseUrl + path + queryParams, {
method: 'GET', method: 'GET',
mode: 'cors', mode: 'cors',
credentials: 'include', credentials: 'include',
@@ -24,7 +26,8 @@ let deleteCall = async (path = "", params = {}) => {
Object.keys(params).forEach(p => { Object.keys(params).forEach(p => {
queryParams += p + "=" + params[p] + "&" queryParams += p + "=" + params[p] + "&"
}); });
return fetch(baseUrl + path + queryParams, { let localBaseUrl = global.baseUrl ?? baseUrl;
return fetch(localBaseUrl + path + queryParams, {
method: 'DELETE', method: 'DELETE',
mode: 'cors', mode: 'cors',
credentials: 'include', credentials: 'include',
@@ -38,7 +41,8 @@ let deleteCall = async (path = "", params = {}) => {
} }
let postCall = async (path, params) => { let postCall = async (path, params) => {
return fetch(baseUrl + path, { let localBaseUrl = global.baseUrl ?? baseUrl;
return fetch(localBaseUrl + path, {
method: 'POST', method: 'POST',
mode: 'cors', mode: 'cors',
credentials: 'include', credentials: 'include',