Hopefully prevent more webserver crashes

This commit is contained in:
calzoneman 2014-02-28 09:04:41 -06:00
parent 5b793710c3
commit d75c8dd230
1 changed files with 37 additions and 23 deletions

View File

@ -138,10 +138,10 @@ function handleIndex(req, res) {
var channels = Server.getServer().packChannelList(true); var channels = Server.getServer().packChannelList(true);
channels.sort(function (a, b) { channels.sort(function (a, b) {
if (a.usercount === b.usercount) { if (a.usercount === b.usercount) {
return a.uniqueName > b.uniqueName ? 1 : -1; return a.uniqueName > b.uniqueName ? -1 : 1;
} }
return a.usercount - b.usercount; return b.usercount - a.usercount;
}); });
sendJade(res, "index", { sendJade(res, "index", {
@ -224,6 +224,7 @@ function handleContactPage(req, res) {
function static(dir) { function static(dir) {
dir = path.join(__dirname, dir); dir = path.join(__dirname, dir);
return function (req, res) { return function (req, res) {
try {
if (isSuspicious(req)) { if (isSuspicious(req)) {
logRequest(req, 403); logRequest(req, 403);
res.status(403); res.status(403);
@ -247,6 +248,10 @@ function static(dir) {
res.send(err.status); res.send(err.status);
} }
}); });
} catch (e) {
Logger.errlog.log(e);
Logger.errlog.log(e.trace);
}
}; };
} }
@ -284,6 +289,15 @@ module.exports = {
require("./account").init(app); require("./account").init(app);
require("./acp").init(app); require("./acp").init(app);
app.use(static(path.join("..", "..", "www"))); app.use(static(path.join("..", "..", "www")));
app.use(function (err, req, res, next) {
if (err) {
Logger.errlog.log(err);
Logger.errlog.log(err.stack);
res.send(500);
} else {
next();
}
});
}, },
logRequest: logRequest, logRequest: logRequest,