From a7d127c7bf3594e3b92beb69ddb89104520f7eec Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Wed, 27 Nov 2024 11:23:42 -0500 Subject: [PATCH] feat: add health check route --- app/routes/healthz.tsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/routes/healthz.tsx diff --git a/app/routes/healthz.tsx b/app/routes/healthz.tsx new file mode 100644 index 0000000..df2bb0e --- /dev/null +++ b/app/routes/healthz.tsx @@ -0,0 +1,29 @@ +import { loadContext } from '~/utils/config/headplane' +import { HeadscaleError, pull } from '~/utils/headscale' +import log from '~/utils/log' + +export async function loader() { + const context = await loadContext() + + try { + // Doesn't matter, we just need a 401 + await pull('v1/', 'wrongkey') + } catch (e) { + if (!(e instanceof HeadscaleError)) { + log.debug('Healthz', 'Headscale is not reachable') + return new Response('Headscale is not reachable', { + status: 500, + headers: { + 'Content-Type': 'text/plain', + }, + }) + } + } + + return new Response('OK', { + status: 200, + headers: { + 'Content-Type': 'text/plain', + }, + }) +}