mirror of
https://github.com/tale/headplane.git
synced 2026-08-19 17:36:19 +00:00
fix: use headscale health route for healthz
This commit is contained in:
+20
-14
@@ -1,26 +1,32 @@
|
|||||||
import { loadContext } from '~/utils/config/headplane';
|
import { loadContext } from '~/utils/config/headplane';
|
||||||
import { HeadscaleError, pull } from '~/utils/headscale';
|
import { HeadscaleError, pull } from '~/utils/headscale';
|
||||||
import { data } from 'react-router';
|
|
||||||
import log from '~/utils/log';
|
import log from '~/utils/log';
|
||||||
|
|
||||||
export async function loader() {
|
export async function loader() {
|
||||||
const context = await loadContext();
|
const context = await loadContext();
|
||||||
|
const prefix = context.headscaleUrl;
|
||||||
|
const health = new URL('health', prefix);
|
||||||
|
log.debug('APIC', 'GET %s', health.toString());
|
||||||
|
let healthy = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Doesn't matter, we just need a 401
|
const res = await fetch(health.toString(), {
|
||||||
await pull('v1/', 'wrongkey');
|
headers: {
|
||||||
} catch (e) {
|
'Accept': 'application/json',
|
||||||
if (!(e instanceof HeadscaleError)) {
|
},
|
||||||
log.debug('Healthz', 'Headscale is not reachable');
|
});
|
||||||
return data(
|
|
||||||
{
|
if (res.status === 200) {
|
||||||
status: 'NOT OK',
|
healthy = true;
|
||||||
error: e.message,
|
|
||||||
},
|
|
||||||
{ status: 500 },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.debug('APIC', 'GET %s failed with error %s', health.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data({ status: 'OK' });
|
return new Response(JSON.stringify({ status: healthy ? 'OK' : 'ERROR' }), {
|
||||||
|
status: healthy ? 200 : 500,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user