From 83fde2186f3c5799f3dcbfac757d2646a1808a9b Mon Sep 17 00:00:00 2001 From: Martii Date: Thu, 7 Apr 2016 12:30:06 -0600 Subject: [PATCH] Create a BUSY landing page * `BUSY_LAG` environment var so this can be twiddled with later * `FORCE_BUSY` environment var to indicate technical difficulties with styling * `FORCE_BUSY_ABSOLUTE` environment var to indicate technical difficulties with no UI * Change the messages to suit **NOTE** This is also to test to see where the memory leak is happening... *mu2* isn't leaking since the hard-coded 503 has been in place and the average memory usage is around ~6% Applies to #944, #249 and #37 --- app.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 3ee5fdaf0..e4a84a9bc 100755 --- a/app.js +++ b/app.js @@ -136,13 +136,36 @@ process.on('SIGINT', function () { var sessionStore = new MongoStore({ mongooseConnection: db }); // See https://hacks.mozilla.org/2013/01/building-a-node-js-server-that-wont-melt-a-node-js-holiday-season-part-5/ -toobusy.maxLag(100); +toobusy.maxLag(process.env.BUSY_LAG || 100); app.use(function (aReq, aRes, aNext) { - // check if we're toobusy - if (toobusy()) { + var pathname = null; + + if (process.env.FORCE_BUSY_ABSOLUTE === 'true') { // check for absolute forced busy + aRes.status(503).send(); // NOTE: No UI period just response header + + } else if (process.env.FORCE_BUSY === 'true') { // check for graceful forced busy + pathname = aReq._parsedUrl.pathname; + + if ( + /^\/favicon\.ico$/.test(pathname) || + /^\/redist\//.test(pathname) || + /^\/less\//.test(pathname) || + /^\/css\//.test(pathname) || + /^\/images\//.test(pathname) || + /^\/fonts\//.test(pathname) + ) { + aNext(); // NOTE: Allow styling pass through on these routes + } else { + statusCodePage(aReq, aRes, aNext, { + statusCode: 503, + statusMessage: + 'We are experiencing technical difficulties right now. Please try again later.' + }); + } + } else if (toobusy()) { // check if we're toobusy statusCodePage(aReq, aRes, aNext, { statusCode: 503, - statusMessage: 'We\'re busy right now. Try again later.' + statusMessage: 'We are busy right now. Please try again later.' }); } else { aNext();