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

Address the app generated 503s #352

Merged
merged 1 commit into from
Sep 30, 2014
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var sessionStore = new MongoStore({ mongoose_connection: db });
// See https://hacks.mozilla.org/2013/01/building-a-node-js-server-that-wont-melt-a-node-js-holiday-season-part-5/
app.use(function (aReq, aRes, aNext) {
// check if we're toobusy
toobusy.maxLag(100);
if (toobusy()) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 503,
Expand Down
28 changes: 28 additions & 0 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ module.exports = function (aApp) {
// Home route
app_route('/').get(main.home);

// Order is important here...
// Only referer check statics otherwise SEO will have issues
aApp.use(function (aReq, aRes, aNext) {
if (process.env.NODE_ENV === 'production'
&& !/^https?:\/\/(?:.*\.)?(?:openuserjs|oujs)\.org/.test(aReq.headers.referer)) {

// Whitelist
switch (aReq.url) {
case '/images/favicon.ico':
case '/images/favicon16.ico':
case '/images/favicon64.png':
case '/xml/opensearch-groups.xml':
case '/xml/opensearch-libraries.xml':
case '/xml/opensearch-scripts.xml':
case '/xml/opensearch-users.xml':
aNext();
break;
default:
statusCodePage(aReq, aRes, aNext, {
statusCode: 404,
statusMessage: 'This is not the page you\'re are looking for!'
});
}
} else {
aNext();
}
});

// Static Routes
require('./routesStatic')(aApp);

Expand Down
2 changes: 1 addition & 1 deletion routesStatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function (aApp) {
}
}

aApp.use(express.static(path.join(__dirname, '/public'), { maxage: day * 1 }));
aApp.use(express.static(path.join(__dirname, 'public'), { maxage: day * 1 }));

serveModule('/redist/npm', 'bootstrap', {
'dist/js/bootstrap.js': { maxage: day * 1 }
Expand Down