Skip to content

Commit

Permalink
feat: add a /health endpoint & use in readiness probe
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jan 26, 2021
1 parent ae31e3d commit ef7c66c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ app.prepare().then(async () => {

server.use('/print-pdf', await printPdf());

// Endpoint /health sends a 500 status if there is an error connecting to the database or if the database is in recovery mode (result.rowAsArray === true)
server.get('/health', ({res}) => {
pgPool.query('SELECT pg_is_in_recovery();', [], (err, result) => {
if (err || result.rowAsArray) {
res.sendStatus(500);
} else {
res.sendStatus(200);
}
});
});

server.get('*', async (req, res) => {
return handle(req, res);
});
Expand Down
2 changes: 1 addition & 1 deletion helm/cas-ciip-portal/templates/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec:
readinessProbe:
failureThreshold: 3
httpGet:
path: /
path: /health
port: {{ .Values.port }}
scheme: HTTP{{ if not .Values.route.insecure }}S{{ end }}
periodSeconds: 10
Expand Down

0 comments on commit ef7c66c

Please sign in to comment.