45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
// Duenner Client des OPS-02-Backends (internal/statuspage) — keine eigene
|
|
// Aggregations-/Polling-Logik im Frontend.
|
|
export type ModuleStatus = {
|
|
name: string;
|
|
status: "up" | "down";
|
|
last_checked?: string;
|
|
};
|
|
|
|
export type HistoryEntry = {
|
|
status: "up" | "down";
|
|
changed_at: string;
|
|
};
|
|
|
|
function apiBase(): string {
|
|
const base = process.env.NEXT_PUBLIC_STATUSPAGE_API_URL;
|
|
if (!base) {
|
|
throw new Error(
|
|
"NEXT_PUBLIC_STATUSPAGE_API_URL ist nicht gesetzt (Umgebungsvariable erforderlich)"
|
|
);
|
|
}
|
|
return base;
|
|
}
|
|
|
|
// fetchOverview holt den Status EINES Moduls unabhaengig vom Erfolg der
|
|
// anderen — ein Netzwerkfehler beim Abruf der Gesamtuebersicht wird vom
|
|
// Aufrufer (Page-Komponente) abgefangen, sodass ein nicht antwortendes
|
|
// Backend die Seite nicht zum Absturz bringt (Akzeptanzkriterium 2).
|
|
export async function fetchOverview(): Promise<ModuleStatus[]> {
|
|
const res = await fetch(`${apiBase()}/status/overview`, { cache: "no-store" });
|
|
if (!res.ok) {
|
|
throw new Error(`Uebersicht konnte nicht geladen werden (${res.status})`);
|
|
}
|
|
return res.json();
|
|
}
|
|
|
|
export async function fetchHistory(name: string): Promise<HistoryEntry[]> {
|
|
const res = await fetch(`${apiBase()}/status/history?name=${encodeURIComponent(name)}`, {
|
|
cache: "no-store",
|
|
});
|
|
if (!res.ok) {
|
|
throw new Error(`Verlauf konnte nicht geladen werden (${res.status})`);
|
|
}
|
|
return res.json();
|
|
}
|