From 08a8fea69af6cdab03e626c0a064845e57ea41e2 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 29 Aug 2021 19:44:06 -0700 Subject: [PATCH] chore: Add /_health endpoint to all services closes #2506 --- server/index.js | 7 +++++++ server/routes/index.js | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/index.js b/server/index.js index 7e06fa5c..4c563803 100644 --- a/server/index.js +++ b/server/index.js @@ -6,6 +6,7 @@ import Koa from "koa"; import compress from "koa-compress"; import helmet from "koa-helmet"; import logger from "koa-logger"; +import Router from "koa-router"; import { uniq } from "lodash"; import stoppable from "stoppable"; import throng from "throng"; @@ -40,7 +41,9 @@ async function start(id, disconnect) { const server = stoppable(http.createServer(app.callback())); const httpLogger = debug("http"); const log = debug("server"); + const router = new Router(); + // install basic middleware shared by all services app.use(logger((str, args) => httpLogger(str))); app.use(compress()); app.use(helmet()); @@ -56,6 +59,10 @@ async function start(id, disconnect) { await init(app, server); } + // install health check endpoint for all services + router.get("/_health", (ctx) => (ctx.body = "OK")); + app.use(router.routes()); + server.on("error", (err) => { throw err; }); diff --git a/server/routes/index.js b/server/routes/index.js index 8f714686..8d827893 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -93,8 +93,6 @@ koa.use( }) ); -router.get("/_health", (ctx) => (ctx.body = "OK")); - if (process.env.NODE_ENV === "production") { router.get("/static/*", async (ctx) => { ctx.set({