chore: use healthcheck method in healthz
This commit is contained in:
parent
1b45b0917f
commit
de9a938da2
@ -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' }), {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user