Skip to content

Commit

Permalink
fix: add health check for backend connection in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemarcoli committed Nov 29, 2024
1 parent efba13e commit 9499285
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ const configureClientMiddleware: Handle = async ({ event, resolve }) => {
if (!event.locals.backendUrl || !event.locals.apiKey) {
throw redirect(307, '/connect');
}

let hasConnection;

try {
await fetch(event.locals.backendUrl + '/api/v1/health')
.then(() => {
hasConnection = true;
})
.catch((error) => {

Check failure on line 37 in src/hooks.server.ts

View workflow job for this annotation

GitHub Actions / Lint

'error' is defined but never used
hasConnection = false;
});
} catch (error) {

Check failure on line 40 in src/hooks.server.ts

View workflow job for this annotation

GitHub Actions / Lint

'error' is defined but never used
hasConnection = false;
}

if (!hasConnection) {
throw redirect(307, '/connect');
}
}

return resolve(event);
Expand Down

0 comments on commit 9499285

Please sign in to comment.