Fix a few minor express issues

This commit is contained in:
calzoneman 2013-11-24 18:13:58 -06:00
parent 7f3561bd27
commit 01464ed394
2 changed files with 16 additions and 20 deletions

View File

@ -31,7 +31,6 @@ var defaults = {
"ip-connection-limit" : 10,
"guest-login-delay" : 60,
"channel-save-interval" : 5,
"trust-x-forward" : false,
"enable-mail" : false,
"mail-transport" : "SMTP",
"mail-config" : {

View File

@ -73,7 +73,9 @@ var Server = function (cfg) {
self.httplog = new Logger.Logger(path.join(__dirname,
"../httpaccess.log"));
self.express = express();
self.express.use(express.bodyParser());
self.express.use(express.urlencoded());
self.express.use(express.json());
self.express.use(express.cookieParser());
// channel route
self.express.get("/r/:channel(*)", function (req, res, next) {
@ -178,24 +180,22 @@ var Server = function (cfg) {
};
Server.prototype.getHTTPIP = function (req) {
var raw = req.connection.remoteAddress;
var forward = req.header("x-forwarded-for");
if((this.cfg["trust-x-forward"] || raw === "127.0.0.1") && forward) {
var ip = forward.split(",")[0];
Logger.syslog.log("REVPROXY " + raw + " => " + ip);
return ip;
var ip = req.ip;
if (ip === "127.0.0.1" || ip === "::1") {
var fwd = req.header("x-forwarded-for");
if (fwd && typeof fwd === "string") {
return fwd;
}
}
return raw;
return ip;
};
Server.prototype.getSocketIP = function (socket) {
var raw = socket.handshake.address.address;
if(this.cfg["trust-x-forward"] || raw === "127.0.0.1") {
if(typeof socket.handshake.headers["x-forwarded-for"] == "string") {
var ip = socket.handshake.headers["x-forwarded-for"]
.split(",")[0];
Logger.syslog.log("REVPROXY " + raw + " => " + ip);
return ip;
if (raw === "127.0.0.1" || raw === "::1") {
var fwd = socket.handshake.headers["x-forwarded-for"];
if (fwd && typeof fwd === "string") {
return fwd;
}
}
return raw;
@ -247,16 +247,13 @@ Server.prototype.logHTTP = function (req, status) {
if (status === undefined)
status = 200;
var ip = req.connection.remoteAddress;
var ip2 = req.header("x-forwarded-for") ||
req.header("cf-connecting-ip");
var ipstr = !ip2 ? ip : ip + " (X-Forwarded-For " + ip2 + ")";
var ip = this.getHTTPIP(req);
var url = req.url;
// Remove query
if(url.indexOf("?") != -1)
url = url.substring(0, url.lastIndexOf("?"));
this.httplog.log([
ipstr,
ip,
req.method,
url,
status,