Skip to content

Commit

Permalink
api: add db and engine checks to healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed May 16, 2024
1 parent b0d115c commit 96e0cdc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,26 @@ const main = async () => {
app.register(harvestersRoutes(ctx)),
]);

app.get("/healthcheck", async (_, reply) => reply.send("OK"));
app.get("/healthcheck", async (_, reply) => {
try {
await ctx.db.$queryRaw`SELECT 1`;
} catch (err) {
return reply
.code(500)
.send({ status: "error", message: "Error connecting to database" });
}

try {
await ctx.engine.default.getJson();
} catch (err) {
return reply.code(500).send({
status: "error",
message: "Error connecting to Thirdweb Engine",
});
}

reply.send({ status: "ok" });
});

// Start server
await app.ready();
Expand Down

0 comments on commit 96e0cdc

Please sign in to comment.