// Duenne fetch()-Wrapper fuer die Phase-1-REST-API (siehe API.md). Reine Daten-Ebene, kein // DOM-Zugriff - office-render.js ruft diese Funktionen auf und reicht die Ergebnisse an die // Layoutlogik (office-scene.js) weiter. Basis-URL ist per window.MONITOR_API_BASE // ueberschreibbar (z.B. wenn Frontend und API auf unterschiedlichen Ports laufen, siehe // docker-compose.yml: web auf :8090, api auf :8091). const DEFAULT_API_BASE = "/api/v1"; function apiBase() { return (typeof window !== "undefined" && window.MONITOR_API_BASE) || DEFAULT_API_BASE; } async function getJson(path) { const response = await fetch(`${apiBase()}${path}`, { headers: { Accept: "application/json" } }); if (!response.ok) { throw new Error(`GET ${path} fehlgeschlagen: HTTP ${response.status}`); } return response.json(); } export async function fetchTickets() { const { tickets } = await getJson("/tickets"); return tickets; } export async function fetchEvents(limit = 200) { const { events } = await getJson(`/events?limit=${encodeURIComponent(limit)}`); return events; } export async function fetchSystems() { const { systems } = await getJson("/systems"); return systems; } export async function fetchKpis() { const { kpis } = await getJson("/kpis"); return kpis; } export async function fetchAgents() { const { agents } = await getJson("/agents"); return agents; } /** * Baut die Stream-URL fuer den SSE-Push-Endpoint (F13, Phase 4). Wird von office-realtime.js * an EventSource() uebergeben. */ export function streamUrl() { return `${apiBase()}/stream`; }