Signed-off-by: Dmytro Stanchiev <git@dmytros.dev>
This commit is contained in:
2026-04-19 17:53:29 -04:00
parent 5800aed751
commit 064ae0f251
59 changed files with 4198 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
let serverAvailable: boolean | null = null
let serverCheckUrl: string | null = null
function delay(milliseconds: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, milliseconds))
}
export async function isServerRunning(serverUrl: string): Promise<boolean> {
if (serverCheckUrl === serverUrl && serverAvailable === true) {
return true
}
const healthUrl = new URL("/global/health", serverUrl).toString()
const timeoutMs = 3000
const maxAttempts = 2
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), timeoutMs)
try {
const response = await fetch(healthUrl, {
signal: controller.signal,
}).catch(() => null)
clearTimeout(timeout)
if (response?.ok) {
serverCheckUrl = serverUrl
serverAvailable = true
return true
}
} finally {
clearTimeout(timeout)
}
if (attempt < maxAttempts) {
await delay(250)
}
}
return false
}
export function resetServerCheck(): void {
serverAvailable = null
serverCheckUrl = null
}