Files
dip-ids/frontend/composables/useBackendStatus.ts
T
kilyabin 78e5c90ed0 feat: healthcheck backend and fix data types
also small various features
2026-04-28 00:10:06 +04:00

25 lines
592 B
TypeScript

// Singleton: один interval на всё приложение
let checkInterval: number | null = null
const isOnline = ref<boolean>(true)
export function useBackendStatus() {
async function check() {
try {
const res = await fetch('/api/health', { signal: AbortSignal.timeout(3000) })
isOnline.value = res.ok
} catch {
isOnline.value = false
}
}
function startPolling() {
if (checkInterval || !import.meta.client) return
check()
checkInterval = window.setInterval(check, 5000)
}
onMounted(startPolling)
return { isOnline, check }
}