diff --git a/.env b/.env index 500da07..3a20681 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ CORS_ALLOWED_ORIGINS=https://dev1.aptivaai.com,http://34.16.120.118:3000,http:// SERVER1_PORT=5000 SERVER2_PORT=5001 SERVER3_PORT=5002 -IMG_TAG=a9421f5-202508081846 +IMG_TAG=6a4d533-202508081922 ENV_NAME=dev PROJECT=aptivaai-dev \ No newline at end of file diff --git a/backend/server1.js b/backend/server1.js index 494dfca..f8e27c2 100755 --- a/backend/server1.js +++ b/backend/server1.js @@ -100,15 +100,19 @@ app.use( }) ); -app.get('/healthz', async (req, res) => { - try { - await verifyCanary(pool); // throws if bad - return res.type('text').send('OK'); // cheap 200 OK - } catch (e) { - console.error('[HEALTHZ]', e.message); - return res.status(500).type('text').send('FAIL'); - } -}); + // LIVENESS: process is up; no external deps + app.get('/healthz', (req, res) => res.type('text').send('OK')); + + // READINESS: KMS/DEK/DB are correct + app.get('/readyz', async (req, res) => { + try { + await verifyCanary(pool); // throws if bad + return res.type('text').send('READY'); + } catch (e) { + console.error('[READYZ]', e.message); + return res.status(503).type('text').send('NOT_READY'); + } + }); // Enable CORS with dynamic origin checking app.use( diff --git a/backend/server2.js b/backend/server2.js index becc295..ecfe083 100755 --- a/backend/server2.js +++ b/backend/server2.js @@ -67,16 +67,20 @@ await verifyCanary(pool); const app = express(); const PORT = process.env.SERVER2_PORT || 5001; -// at top of backend/server.js (do once per server codebase) -app.get('/healthz', async (req, res) => { - try { - await verifyCanary(pool); // << just pass the pool - return res.type('text').send('OK'); - } catch (e) { - console.error('[HEALTHZ]', e.message); - return res.status(500).type('text').send('FAIL'); - } -}); + // LIVENESS: process is up; no external deps + app.get('/healthz', (req, res) => res.type('text').send('OK')); + + // READINESS: KMS/DEK/DB are correct + app.get('/readyz', async (req, res) => { + try { + await verifyCanary(pool); // throws if bad + return res.type('text').send('READY'); + } catch (e) { + console.error('[READYZ]', e.message); + return res.status(503).type('text').send('NOT_READY'); + } + }); + /************************************************** * DB connections diff --git a/backend/server3.js b/backend/server3.js index f252c15..95ad6ad 100644 --- a/backend/server3.js +++ b/backend/server3.js @@ -71,16 +71,20 @@ const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { apiVersion: '2024-04-10', }); -// at top of backend/server.js (do once per server codebase) -app.get('/healthz', async (req, res) => { - try { - await verifyCanary(pool); // << just pass the pool - return res.type('text').send('OK'); - } catch (e) { - console.error('[HEALTHZ]', e.message); - return res.status(500).type('text').send('FAIL'); - } -}); + // LIVENESS: process is up; no external deps + app.get('/healthz', (req, res) => res.type('text').send('OK')); + + // READINESS: KMS/DEK/DB are correct + app.get('/readyz', async (req, res) => { + try { + await verifyCanary(pool); // throws if bad + return res.type('text').send('READY'); + } catch (e) { + console.error('[READYZ]', e.message); + return res.status(503).type('text').send('NOT_READY'); + } + }); + function internalFetch(req, urlPath, opts = {}) { return fetch(`${API_BASE}${urlPath}`, {