headplane/app/routes/util/healthz.ts

24 lines
560 B
TypeScript
Raw Normal View History

2024-11-27 11:23:42 -05:00
import { loadContext } from '~/utils/config/headplane'
import { HeadscaleError, pull } from '~/utils/headscale'
2024-12-08 13:52:02 -05:00
import { data } from '@remix-run/node'
2024-11-27 11:23:42 -05:00
import log from '~/utils/log'
export async function loader() {
const context = await loadContext()
try {
// Doesn't matter, we just need a 401
await pull('v1/', 'wrongkey')
} catch (e) {
if (!(e instanceof HeadscaleError)) {
log.debug('Healthz', 'Headscale is not reachable')
2024-12-08 13:52:02 -05:00
return data({
status: 'NOT OK',
error: e.message
}, { status: 500 })
2024-11-27 11:23:42 -05:00
}
}
2024-12-08 13:52:02 -05:00
return { status: 'OK' }
2024-11-27 11:23:42 -05:00
}