Skip to content

Commit 7abdc97

Browse files
committed
feat: add health check endpoints for application status and GraphQL API readiness
1 parent 409971a commit 7abdc97

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/routes/isAlive/+server.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { json } from '@sveltejs/kit';
2+
3+
export function GET() {
4+
return json({ status: 'ok' });
5+
}

src/routes/isReady/+server.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { json } from '@sveltejs/kit';
2+
3+
const GRAPHQL_API_URL = process.env.VITE_GRAPHQL_ENDPOINT || 'http://localhost:3000/graphql';
4+
5+
async function checkGraphQLAPI() {
6+
try {
7+
const response = await fetch(GRAPHQL_API_URL, {
8+
method: 'POST'
9+
});
10+
11+
if (response.status === 401) {
12+
return true;
13+
}
14+
15+
return response.ok;
16+
} catch (error) {
17+
console.log(error);
18+
return false;
19+
}
20+
}
21+
22+
let isAppReady = false;
23+
24+
async function ready() {
25+
isAppReady = await checkGraphQLAPI();
26+
setTimeout(ready, 1000);
27+
}
28+
29+
ready();
30+
31+
export async function GET() {
32+
return json(
33+
{ status: isAppReady ? 'ready' : 'waiting-for-api' },
34+
{ status: isAppReady ? 200 : 503 }
35+
);
36+
}

0 commit comments

Comments
 (0)