fix teacher, parent and admin pages
This commit is contained in:
+19
-3
@@ -1,12 +1,28 @@
|
||||
/** Prefix for Laravel API when the SPA is served from another origin (production). Empty in dev with Vite proxy. */
|
||||
const PROD_API_ORIGIN = 'https://api.alrahmaisgl.org'
|
||||
|
||||
/**
|
||||
* Laravel API base URL.
|
||||
*
|
||||
* **Vite dev:** same-origin `/api/...`; `vite.config.ts` proxies to the API (default `http://192.168.3.100:8000`).
|
||||
* Override proxy target with **`VITE_PROXY_API`**. **`VITE_API_ORIGIN` is not used in dev** (avoids cross-origin from the browser).
|
||||
*
|
||||
* **Production build:** `VITE_API_ORIGIN` if set, else `PROD_API_ORIGIN`.
|
||||
*/
|
||||
export function apiOrigin(): string {
|
||||
if (import.meta.env.DEV) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const v = import.meta.env.VITE_API_ORIGIN
|
||||
const fallback = 'https://api.alrahmaisgl.org'
|
||||
return typeof v === 'string' && v.trim() ? v.replace(/\/$/, '') : fallback
|
||||
if (typeof v === 'string' && v.trim()) {
|
||||
return v.replace(/\/$/, '')
|
||||
}
|
||||
return PROD_API_ORIGIN
|
||||
}
|
||||
|
||||
export function apiUrl(path: string): string {
|
||||
const base = apiOrigin()
|
||||
const p = path.startsWith('/') ? path : `/${path}`
|
||||
if (!base) return p
|
||||
return `${base}${p}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user