diff --git a/server.js b/server.js index 29e953d..ed8be17 100644 --- a/server.js +++ b/server.js @@ -85,31 +85,25 @@ async function docsHandler(req, res) { res.end('Documentation file not found'); } -async function readyz(_req, res) { +async function health(_req, res) { if (!S3_BUCKET) { - res.statusCode = 200; - res.end(JSON.stringify({ status: 'ready', s3: 'not configured' })); + res.statusCode = 503; + res.end('s3 unreachable: S3_BUCKET not configured'); return; } try { await s3.send(new HeadBucketCommand({ Bucket: S3_BUCKET })); res.statusCode = 200; - res.end(JSON.stringify({ status: 'ready', s3: 'ok' })); - } catch (_error) { + res.end('ok'); + } catch (error) { res.statusCode = 503; - res.end(JSON.stringify({ status: 'not ready', s3: 'unavailable' })); + res.end('s3 unreachable: ' + (error && error.message ? error.message : error)); } } const server = http.createServer((req, res) => { - if (req.url === '/healthz') { - res.statusCode = 200; - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify({ status: 'ok', version: VERSION })); - return; - } - if (req.url === '/readyz') { - readyz(req, res); + if (req.url === '/health') { + health(req, res); return; } if (req.url.startsWith('/docs/')) {