|
1
|
/** |
|
2
|
* Global Configuration for JCRguru |
|
3
|
*/ |
|
4
|
|
|
5
|
const STORAGE_KEY = "jcrguru_api_base_url"; |
|
6
|
|
|
7
|
// Default to relative /api if not specified, |
|
8
|
// but in hybrid mode we might need to point to a specific IP or domain. |
|
9
|
const DEFAULT_API_URL = window.location.origin.includes("androidplatform.net") |
|
10
|
? "https://jcr-guide-pro.replit.app" // Fallback to production if in hybrid local shell |
|
11
|
: ""; |
|
12
|
|
|
13
|
export const getApiBaseUrl = (): string => { |
|
14
|
return localStorage.getItem(STORAGE_KEY) || DEFAULT_API_URL; |
|
15
|
}; |
|
16
|
|
|
17
|
export const setApiBaseUrl = (url: string) => { |
|
18
|
if (!url) { |
|
19
|
localStorage.removeItem(STORAGE_KEY); |
|
20
|
} else { |
|
21
|
// Ensure no trailing slash |
|
22
|
const formattedUrl = url.replace(/\/$/, ""); |
|
23
|
localStorage.setItem(STORAGE_KEY, formattedUrl); |
|
24
|
} |
|
25
|
}; |
|
26
|
|
|
27
|
/** |
|
28
|
* Helper to construct API URLs |
|
29
|
*/ |
|
30
|
export const apiurl = (path: string): string => { |
|
31
|
const base = getApiBaseUrl(); |
|
32
|
// Ensure path starts with / |
|
33
|
const formattedPath = path.startsWith("/") ? path : `/${path}`; |
|
34
|
return `${base}${formattedPath}`; |
|
35
|
}; |