From 61a62527f3db2c1b84c6bc9e753963b3845c7b31 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Mon, 4 Dec 2023 22:10:48 +0000 Subject: [PATCH] Add healthcheck for each express instance. Instance accepts /health query on listening port. --- controllers/routes.js | 5 +++-- downloader.js | 8 ++++++++ uploader.js | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/controllers/routes.js b/controllers/routes.js index 83cb36046..ec6286a77 100644 --- a/controllers/routes.js +++ b/controllers/routes.js @@ -321,8 +321,9 @@ export function bindRoutes(app) { }); // Ping-pong to verify the server is working - app.all('/ping', (req, res) => { - res.status(200).send('pong'); + app.all('/health', (req, res) => { + res.set('Cache-Control', 'no-store'); + res.status(200).send('OK'); }); // Last handler. If request reaches it, means that there is no handler for this request diff --git a/downloader.js b/downloader.js index 3cbee5034..e357b7149 100644 --- a/downloader.js +++ b/downloader.js @@ -302,6 +302,14 @@ export async function configure(startStamp) { // Start server and do manual manual url router, express is not needed const server = http .createServer(function handleRequest(req, res) { + if (req.url === '/health') { + res.setHeader('Cache-Control', 'no-store'); + res.statusCode = 200; + res.end('OK'); + + return; + } + if (protectedServePattern.test(req.url)) { return protectedHandler(req, res); } diff --git a/uploader.js b/uploader.js index 6dc0a1faa..3df8c404b 100644 --- a/uploader.js +++ b/uploader.js @@ -268,6 +268,14 @@ export function configure(startStamp) { }; const handleRequest = (req, res) => { + if (req.url === '/health') { + res.setHeader('Cache-Control', 'no-store'); + res.statusCode = 200; + res.end('OK'); + + return; + } + if (req.url !== '/upload' && req.url !== '/uploadava') { res.statusCode = 403; res.end();