Bisher war /hifi an mehreren Stellen fest einprogrammiert (vite base, Router basename, API-Client, Upload-URLs, .htaccess). Fuer den geplanten Deploy auf IONOS unter der Domain-Wurzel wird das jetzt ueber VITE_BASE_PATH (Frontend-Build) bzw. eine optionale base_path.php (Backend, gleiches Muster wie db.php/setup.php) gesteuert - lokal ohne diese Werte bleibt alles unveraendert bei /hifi. .htaccess.ionos enthaelt die Root-Domain-Variante fuer den CI-Build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
// BASE_URL spiegelt immer den "base"-Wert aus vite.config.js wider (mit
|
|
// abschließendem Slash, z.B. "/hifi/" lokal oder "/" auf IONOS).
|
|
export const API_BASE = `${import.meta.env.BASE_URL.replace(/\/$/, '')}/api`;
|
|
|
|
async function request(path, options = {}) {
|
|
const res = await fetch(`${API_BASE}${path}`, {
|
|
credentials: 'include',
|
|
headers: options.body instanceof FormData ? {} : { 'Content-Type': 'application/json' },
|
|
...options,
|
|
});
|
|
|
|
const isJson = res.headers.get('content-type')?.includes('application/json');
|
|
const data = isJson ? await res.json() : null;
|
|
|
|
if (!res.ok) {
|
|
throw new Error(data?.error || `Fehler ${res.status}`);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
export const api = {
|
|
get: (path) => request(path),
|
|
post: (path, body) => request(path, { method: 'POST', body: body instanceof FormData ? body : JSON.stringify(body) }),
|
|
put: (path, body) => request(path, { method: 'PUT', body: JSON.stringify(body) }),
|
|
patch: (path, body) => request(path, { method: 'PATCH', body: JSON.stringify(body) }),
|
|
delete: (path) => request(path, { method: 'DELETE' }),
|
|
};
|