Skip to content

Commit 9499285

Browse files
committed
fix: add health check for backend connection in middleware
1 parent efba13e commit 9499285

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/hooks.server.ts

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ const configureClientMiddleware: Handle = async ({ event, resolve }) => {
2626
if (!event.locals.backendUrl || !event.locals.apiKey) {
2727
throw redirect(307, '/connect');
2828
}
29+
30+
let hasConnection;
31+
32+
try {
33+
await fetch(event.locals.backendUrl + '/api/v1/health')
34+
.then(() => {
35+
hasConnection = true;
36+
})
37+
.catch((error) => {
38+
hasConnection = false;
39+
});
40+
} catch (error) {
41+
hasConnection = false;
42+
}
43+
44+
if (!hasConnection) {
45+
throw redirect(307, '/connect');
46+
}
2947
}
3048

3149
return resolve(event);

0 commit comments

Comments
 (0)