generated from Dicken/dickendock
Commit 6: Adminbereich (TanStack Router, 8 Menüpunkte, Scan-Logs)
This commit is contained in:
34
apps/frontend/src/hooks/useBackendHealth.ts
Normal file
34
apps/frontend/src/hooks/useBackendHealth.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import type { HealthStatus } from "@launchpad/shared";
|
||||
|
||||
export function useBackendHealth() {
|
||||
const [health, setHealth] = useState<HealthStatus | null>(null);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
async function check() {
|
||||
try {
|
||||
const res = await fetch("/api/health");
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const data: HealthStatus = await res.json();
|
||||
if (!cancelled) {
|
||||
setHealth(data);
|
||||
setError(false);
|
||||
}
|
||||
} catch {
|
||||
if (!cancelled) setError(true);
|
||||
}
|
||||
}
|
||||
|
||||
check();
|
||||
const interval = setInterval(check, 10_000);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { health, error };
|
||||
}
|
||||
Reference in New Issue
Block a user