mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-03-30 11:16:35 +00:00
feat: add healthz endpoint (#494)
This commit is contained in:
committed by
GitHub
parent
c55fef057c
commit
3c87e4ec14
@@ -1,20 +1,2 @@
|
||||
import AppConfigService from '$lib/services/app-config-service';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
const appConfigService = new AppConfigService();
|
||||
let backendOk = true;
|
||||
await appConfigService.list().catch(() => (backendOk = false));
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
status: backendOk ? 'HEALTHY' : 'UNHEALTHY'
|
||||
}),
|
||||
{
|
||||
status: backendOk ? 200 : 500,
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
// /health is an alias of /healthz, for backwards-compatibility reasons
|
||||
export {GET} from '../healthz/+server';
|
||||
|
||||
18
frontend/src/routes/healthz/+server.ts
Normal file
18
frontend/src/routes/healthz/+server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import axios from 'axios';
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
const backendOK = await axios
|
||||
.get(process!.env!.INTERNAL_BACKEND_URL + '/healthz')
|
||||
.then(() => true, () => false);
|
||||
|
||||
return new Response(
|
||||
backendOK ? `{"status":"HEALTHY"}` : `{"status":"UNHEALTHY"}`,
|
||||
{
|
||||
status: backendOK ? 200 : 500,
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user