Skip to content

Commit cd0daa6

Browse files
committed
fix: server-side API probe, component tests, CI lint gate, docs parity
1 parent 3f0a1e7 commit cd0daa6

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

‎src/components/LiveStatus.tsx‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,38 @@ const DOT: Record<State, string> = {
1616
down: 'bg-rose-500',
1717
};
1818

19-
export function LiveStatus() {
19+
const PROBE_TIMEOUT_MS = 30_000;
20+
21+
export function LiveStatus({ apiUrl }: { apiUrl: string }) {
2022
const [state, setState] = useState<State>('loading');
2123

2224
useEffect(() => {
23-
let active = true;
24-
const base = process.env.NEXT_PUBLIC_API_URL;
25-
if (!base) {
25+
if (!apiUrl) {
2626
setState('down');
2727
return;
2828
}
29-
fetch(`${base}/health/ready/`)
29+
30+
let active = true;
31+
const controller = new AbortController();
32+
const timeout = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS);
33+
const base = apiUrl.replace(/\/+$/, '');
34+
35+
fetch(`${base}/health/ready/`, { signal: controller.signal })
3036
.then((res) => (res.ok ? res.json() : Promise.reject(new Error(String(res.status)))))
3137
.then((payload) => {
3238
if (active) setState(payload?.status === 'ok' ? 'ok' : 'down');
3339
})
3440
.catch(() => {
3541
if (active) setState('down');
36-
});
42+
})
43+
.finally(() => clearTimeout(timeout));
44+
3745
return () => {
3846
active = false;
47+
clearTimeout(timeout);
48+
controller.abort();
3949
};
40-
}, []);
50+
}, [apiUrl]);
4151

4252
return (
4353
<div

0 commit comments

Comments
 (0)