Skip to content

Commit

Permalink
Closes #81
Browse files Browse the repository at this point in the history
  • Loading branch information
osoner committed Aug 9, 2014
1 parent a949115 commit 9899b3d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ function validateUserForMgmtReadAPI(callback, params) {
});
}

function getIpAddress(req) {
var ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;

/* Since x-forwarded-for: client, proxy1, proxy2, proxy3 */
return ipAddress.split(',')[0];
}

if (cluster.isMaster) {

var workerCount = (common.config.api.workers)? common.config.api.workers : os.cpus().length;
Expand Down Expand Up @@ -297,9 +304,7 @@ if (cluster.isMaster) {
}
case '/i':
{
var ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

params.ip_address = params.qstring.ip_address || ipAddress.split(",")[0];
params.ip_address = getIpAddress(req);
params.user = {
'country':'Unknown',
'city':'Unknown'
Expand Down

0 comments on commit 9899b3d

Please sign in to comment.