headplane/app/routes/util/healthz.ts

33 lines
800 B
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { loadContext } from '~/utils/config/headplane';
import { HeadscaleError, pull } from '~/utils/headscale';
import log from '~/utils/log';
2024-11-27 11:23:42 -05:00
export async function loader() {
2024-12-31 10:30:14 +05:30
const context = await loadContext();
const prefix = context.headscaleUrl;
const health = new URL('health', prefix);
log.debug('APIC', 'GET %s', health.toString());
let healthy = false
2024-11-27 11:23:42 -05:00
try {
const res = await fetch(health.toString(), {
headers: {
'Accept': 'application/json',
},
});
if (res.status === 200) {
healthy = true;
2024-11-27 11:23:42 -05:00
}
} catch (e) {
log.debug('APIC', 'GET %s failed with error %s', health.toString(), e);
2024-11-27 11:23:42 -05:00
}
return new Response(JSON.stringify({ status: healthy ? 'OK' : 'ERROR' }), {
status: healthy ? 200 : 500,
headers: {
'Content-Type': 'application/json',
},
});
2024-11-27 11:23:42 -05:00
}