chore: init monorepo snapshot

This commit is contained in:
liaibo
2025-11-23 10:55:04 +08:00
commit c70ff52869
941 changed files with 246586 additions and 0 deletions
@@ -0,0 +1,40 @@
import { useEffect, useState } from "react";
type Status = "idle" | "ok" | "error";
export function useBackendHealth() {
const [status, setStatus] = useState<Status>(() => {
if (!process.env.NEXT_PUBLIC_BACKEND_URL) {
return "error";
}
return "idle";
});
useEffect(() => {
let destroyed = false;
const url = process.env.NEXT_PUBLIC_BACKEND_URL;
if (!url) {
return;
}
const controller = new AbortController();
const check = async () => {
try {
const response = await fetch(`${url}/health`, { signal: controller.signal });
if (!destroyed) {
setStatus(response.ok ? "ok" : "error");
}
} catch {
if (!destroyed) {
setStatus("error");
}
}
};
check();
return () => {
destroyed = true;
controller.abort();
};
}, []);
return status;
}