x
This commit is contained in:
1 parent
927f03a8b7
commit
4c38f2a596
5 files changed
+83
-6
No files matched your search
+25
-3
@@ -59,9 +59,31 @@ export interface Product {
|
||||
images: ProductImage[]
|
||||
}
|
||||
|
||||
export const API_BASE = (typeof import.meta !== 'undefined' && (import.meta as any).env?.VITE_API_URL)
|
||||
|| ((globalThis as any).process?.env?.VITE_API_URL)
|
||||
|| 'http://localhost:3000/api'
|
||||
const DEFAULT_DEV_API_PORT = 3051
|
||||
|
||||
function resolveApiBase() {
|
||||
const viteEnv = (typeof import.meta !== 'undefined' ? (import.meta as any).env : undefined)
|
||||
const envValue = viteEnv?.VITE_API_URL || (globalThis as any).process?.env?.VITE_API_URL
|
||||
|
||||
if (envValue) {
|
||||
const isDev = Boolean(viteEnv?.DEV)
|
||||
const isLocalhostUrl = /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?\/api\/?$/.test(envValue)
|
||||
|
||||
if (isDev && typeof window !== 'undefined' && isLocalhostUrl) {
|
||||
return `${window.location.protocol}//${window.location.hostname}:${DEFAULT_DEV_API_PORT}/api`
|
||||
}
|
||||
|
||||
return envValue
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
return `${window.location.protocol}//${window.location.hostname}:${DEFAULT_DEV_API_PORT}/api`
|
||||
}
|
||||
|
||||
return 'http://localhost:3000/api'
|
||||
}
|
||||
|
||||
export const API_BASE = resolveApiBase()
|
||||
|
||||
export const CATEGORY_IMAGES: Record<string, string> = {
|
||||
'Oil Ozone': '/images/oil_ozone.png',
|
||||
|
||||
Reference in new issue
Block a user