feat: replace /healthz + /readyz with single /health (real S3 check)
This commit is contained in:
@@ -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/')) {
|
||||
|
||||
Reference in New Issue
Block a user