headplane/app/routes/util/healthz.ts

27 lines
583 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 { data } from 'react-router';
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();
2024-11-27 11:23:42 -05:00
try {
// Doesn't matter, we just need a 401
2024-12-31 10:30:14 +05:30
await pull('v1/', 'wrongkey');
2024-11-27 11:23:42 -05:00
} catch (e) {
if (!(e instanceof HeadscaleError)) {
2024-12-31 10:30:14 +05:30
log.debug('Healthz', 'Headscale is not reachable');
return data(
{
status: 'NOT OK',
error: e.message,
},
{ status: 500 },
);
2024-11-27 11:23:42 -05:00
}
}
2024-12-31 10:30:14 +05:30
return { status: 'OK' };
2024-11-27 11:23:42 -05:00
}