From 757ec4358ab4face5fbfac4d61326ae0450f8a15 Mon Sep 17 00:00:00 2001 From: ngosang Date: Sun, 4 Apr 2021 20:33:07 +0200 Subject: [PATCH] Add health check endpoint --- src/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.ts b/src/index.ts index 4d1ef7d..d8e969a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,6 +92,16 @@ validateEnvironmentVariables(); createServer((req: IncomingMessage, res: ServerResponse) => { const startTimestamp = Date.now() + // health endpoint. this endpoint is special because it doesn't print traces + if (req.url == '/health') { + res.writeHead(200, { + 'Content-Type': 'application/json' + }) + res.write(JSON.stringify({"status": "ok"})) + res.end() + return; + } + // count the request for the log prefix log.incRequests() log.info(`Incoming request: ${req.method} ${req.url}`)