From 539c76dfb3c910c30a160c246599269b33242ad8 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Sat, 18 Jan 2025 07:38:55 +0000 Subject: [PATCH] chore: switch to shared healtcheck func --- app/utils/headscale.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/utils/headscale.ts b/app/utils/headscale.ts index 18d9d14..b85741a 100644 --- a/app/utils/headscale.ts +++ b/app/utils/headscale.ts @@ -20,6 +20,22 @@ export class FatalError extends Error { } } +export async function healthcheck() { + const context = await loadContext(); + const prefix = context.headscaleUrl; + log.debug('APIC', 'GET /health'); + + const health = new URL('health', prefix); + const response = await fetch(health.toString(), { + headers: { + Accept: 'application/json' + } + }) + + // Intentionally not catching + return response.status === 200; +} + export async function pull(url: string, key: string) { if (!key || key === 'undefined' || key.length === 0) { throw new Error('Missing API key, could this be a cookie setting issue?');