Skip to content

Commit

Permalink
Merge pull request #645 from kabalin/health
Browse files Browse the repository at this point in the history
Add healthcheck for each express instance.
  • Loading branch information
kabalin authored Dec 4, 2023
2 parents 81c23c0 + 61a6252 commit f27e0df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions controllers/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f27e0df

Please sign in to comment.