78e5c90ed0
also small various features
25 lines
592 B
TypeScript
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 }
|
|
}
|