Skip to content

Commit 9899b3d

Browse files
committed
Closes Countly#81
1 parent a949115 commit 9899b3d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

api/api.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ function validateUserForMgmtReadAPI(callback, params) {
117117
});
118118
}
119119

120+
function getIpAddress(req) {
121+
var ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
122+
123+
/* Since x-forwarded-for: client, proxy1, proxy2, proxy3 */
124+
return ipAddress.split(',')[0];
125+
}
126+
120127
if (cluster.isMaster) {
121128

122129
var workerCount = (common.config.api.workers)? common.config.api.workers : os.cpus().length;
@@ -297,9 +304,7 @@ if (cluster.isMaster) {
297304
}
298305
case '/i':
299306
{
300-
var ipAddress = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
301-
302-
params.ip_address = params.qstring.ip_address || ipAddress.split(",")[0];
307+
params.ip_address = getIpAddress(req);
303308
params.user = {
304309
'country':'Unknown',
305310
'city':'Unknown'

0 commit comments

Comments
 (0)