chore: use healthcheck method in healthz

This commit is contained in:
Aarnav Tale 2025-01-17 11:46:36 +00:00
parent 1b45b0917f
commit de9a938da2
No known key found for this signature in database

View File

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