Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a BUSY landing page #947

Merged
merged 1 commit into from
Apr 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down