diff --git a/app/routes/util/healthz.ts b/app/routes/util/healthz.ts index 9720598..9cc910e 100644 --- a/app/routes/util/healthz.ts +++ b/app/routes/util/healthz.ts @@ -1,26 +1,12 @@ -import { loadContext } from '~/utils/config/headplane'; -import { HeadscaleError, pull } from '~/utils/headscale'; +import { healthcheck } from '~/utils/headscale'; import log from '~/utils/log'; export async function loader() { - const context = await loadContext(); - const prefix = context.headscaleUrl; - const health = new URL('health', prefix); - log.debug('APIC', 'GET %s', health.toString()); - let healthy = false - + let healthy = false; try { - const res = await fetch(health.toString(), { - headers: { - 'Accept': 'application/json', - }, - }); - - if (res.status === 200) { - healthy = true; - } - } catch (e) { - log.debug('APIC', 'GET %s failed with error %s', health.toString(), e); + healthy = await healthcheck(); + } catch (error) { + log.debug('APIC', 'Healthcheck failed %o', error); } return new Response(JSON.stringify({ status: healthy ? 'OK' : 'ERROR' }), {