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');
|
res.end('Documentation file not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readyz(_req, res) {
|
async function health(_req, res) {
|
||||||
if (!S3_BUCKET) {
|
if (!S3_BUCKET) {
|
||||||
res.statusCode = 200;
|
res.statusCode = 503;
|
||||||
res.end(JSON.stringify({ status: 'ready', s3: 'not configured' }));
|
res.end('s3 unreachable: S3_BUCKET not configured');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await s3.send(new HeadBucketCommand({ Bucket: S3_BUCKET }));
|
await s3.send(new HeadBucketCommand({ Bucket: S3_BUCKET }));
|
||||||
res.statusCode = 200;
|
res.statusCode = 200;
|
||||||
res.end(JSON.stringify({ status: 'ready', s3: 'ok' }));
|
res.end('ok');
|
||||||
} catch (_error) {
|
} catch (error) {
|
||||||
res.statusCode = 503;
|
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) => {
|
const server = http.createServer((req, res) => {
|
||||||
if (req.url === '/healthz') {
|
if (req.url === '/health') {
|
||||||
res.statusCode = 200;
|
health(req, res);
|
||||||
res.setHeader('Content-Type', 'application/json');
|
|
||||||
res.end(JSON.stringify({ status: 'ok', version: VERSION }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (req.url === '/readyz') {
|
|
||||||
readyz(req, res);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (req.url.startsWith('/docs/')) {
|
if (req.url.startsWith('/docs/')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user