Build, test and deploy Required
Give the server a health check
Give the server a health check address that tests its real dependencies, so deploys and monitors know when it is broken.
How to do it
Add an address such as /healthz that runs a cheap query against the database and other dependencies. Answer 200 when all work and 503 when one fails. Keep it fast and free of private data. The one-step deploy polls it and rolls back on failure. For more depth, see liveness and readiness.
Example
app.get('/healthz', (req, res) => {
try {
db.prepare('SELECT 1').get();
res.type('text').send('ok');
} catch {
res.status(503).type('text').send('database unavailable');
}
});
How to check
Stop a dependency on a test server. The health check answers 503 within a second.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers engineering playbook: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/health-check-and-rollback.