From c8f99388657d679efde9c4407bbaa34fb4ee543f Mon Sep 17 00:00:00 2001 From: Stevche Radevski Date: Thu, 26 Dec 2024 13:53:12 +0800 Subject: [PATCH] feat(medusa): Add health endpoint for all running modes of medusa (#10737) --- packages/core/framework/src/http/express-loader.ts | 4 ---- packages/medusa/src/commands/start.ts | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/framework/src/http/express-loader.ts b/packages/core/framework/src/http/express-loader.ts index 94738b662fa5c..78497daec8cb2 100644 --- a/packages/core/framework/src/http/express-loader.ts +++ b/packages/core/framework/src/http/express-loader.ts @@ -95,10 +95,6 @@ export async function expressLoader({ app }: { app: Express }): Promise<{ // Currently we don't allow configuration of static files, but this can be revisited as needed. app.use("/static", express.static(path.join(baseDir, "static"))) - app.get("/health", (req, res) => { - res.status(200).send("OK") - }) - const shutdown = async () => { redisClient?.disconnect() } diff --git a/packages/medusa/src/commands/start.ts b/packages/medusa/src/commands/start.ts index 91bc1a30fc174..f5e48f1a2acef 100644 --- a/packages/medusa/src/commands/start.ts +++ b/packages/medusa/src/commands/start.ts @@ -138,6 +138,12 @@ async function start(args: { } const serverActivity = logger.activity(`Creating server`) + + // Register a health check endpoint. Ideally this also checks the readiness of the service, rather than just returning a static response. + app.get("/health", (_, res) => { + res.status(200).send("OK") + }) + const server = GracefulShutdownServer.create( http_.listen(port, host).on("listening", () => { logger.success(