From 62e410c6cab5f3972fa5b1cdd05172bdc92e1e86 Mon Sep 17 00:00:00 2001 From: Alain Nicolas Date: Thu, 5 Dec 2024 19:01:48 +0100 Subject: [PATCH] chore: Split healthcheck and readiness endpoints --- packages/linea-ccip-gateway/package.json | 4 ++-- packages/linea-ccip-gateway/src/server.ts | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/linea-ccip-gateway/package.json b/packages/linea-ccip-gateway/package.json index 69762984e..75a582305 100644 --- a/packages/linea-ccip-gateway/package.json +++ b/packages/linea-ccip-gateway/package.json @@ -1,6 +1,6 @@ { "name": "@consensys/linea-ccip-gateway", - "version": "1.0.1", + "version": "1.1.0", "main": "dist/index.js", "author": "Consensys", "license": "Apache-2.0", @@ -53,4 +53,4 @@ "@types/supertest": "^2.0.14", "nyc": "^15.1.0" } -} \ No newline at end of file +} diff --git a/packages/linea-ccip-gateway/src/server.ts b/packages/linea-ccip-gateway/src/server.ts index 6e3f39087..7cdecce64 100644 --- a/packages/linea-ccip-gateway/src/server.ts +++ b/packages/linea-ccip-gateway/src/server.ts @@ -28,12 +28,20 @@ try { console.log("Server setup complete."); - // Add a health check page + // Healthcheck endpoint app.get("/health", async (_req, res, _next) => { - const healthcheck = { + res.send({ uptime: process.uptime(), message: "OK", timestamp: Date.now(), + }); + }); + + // Liveness probe + app.get("/ready", async (_req, res, _next) => { + const readiness = { + message: "OK", + timestamp: Date.now(), }; try { const host = _req.protocol + "://" + _req.get("host"); @@ -47,15 +55,15 @@ try { } const check = await fetch(urlToCheck); if (check.status != 200) { - healthcheck.message = check.statusText; - logError(healthcheck); + readiness.message = check.statusText; + logError(readiness); res.status(check.status).send(); } else { - res.send(healthcheck); + res.send(readiness); } } catch (error) { - healthcheck.message = error; - logError(error, healthcheck); + readiness.message = error; + logError(error, readiness); res.status(500).send(); } });