Skip to content

Commit

Permalink
chore: Split healthcheck and readiness endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
alainncls committed Dec 6, 2024
1 parent 936f88b commit 115bd56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/linea-ccip-gateway/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -53,4 +53,4 @@
"@types/supertest": "^2.0.14",
"nyc": "^15.1.0"
}
}
}
24 changes: 16 additions & 8 deletions packages/linea-ccip-gateway/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ try {

console.log("Server setup complete.");

// Add a health check page
app.get("/health", async (_req, res, _next) => {
const healthcheck = {
// Liveness probe
app.get("/live", async (_req, res, _next) => {
res.send({
uptime: process.uptime(),
message: "OK",
timestamp: Date.now(),
});
});

// Readiness probe
app.get("/ready", async (_req, res, _next) => {
const readiness = {
message: "OK",
timestamp: Date.now(),
};
try {
const host = _req.protocol + "://" + _req.get("host");
Expand All @@ -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();
}
});
Expand Down

0 comments on commit 115bd56

Please sign in to comment.