f13a63dc2f
- Custom ToastContext + ToastProvider + ToastContainer (~170 lines, no deps) - useEvents() SSE hook with exponential backoff reconnect - EventProvider context for app-wide SSE stream sharing - Event-to-toast bridge with severity mapping and deduplication - Real-time status badge updates replacing 30s polling - EventSource auth probe (401/429 detection via fetch) - 14 frontend tests (useEvents + toast-rules) Quality gates: vitest 14 passed, tsc clean, eslint clean
23 lines
598 B
TypeScript
23 lines
598 B
TypeScript
const BASE_URL = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8000";
|
|
|
|
export function createEventSource(): EventSource {
|
|
return new EventSource(`${BASE_URL}/events/stream`, {
|
|
withCredentials: true,
|
|
});
|
|
}
|
|
|
|
export async function probeEventStreamStatus(): Promise<number | null> {
|
|
try {
|
|
const controller = new AbortController();
|
|
const timer = setTimeout(() => controller.abort(), 2000);
|
|
const res = await fetch(`${BASE_URL}/events/stream`, {
|
|
credentials: "include",
|
|
signal: controller.signal,
|
|
});
|
|
clearTimeout(timer);
|
|
return res.status;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|