util.js
427 Bytes
'use strict';
const _ = require('lodash');
const getClientIp = req => {
let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || req.ip;
if (remoteIp.indexOf(',') > 0) {
const arr = remoteIp.split(',');
remoteIp = _.trim(arr[arr.length - 1]);
}
if (_.startsWith(remoteIp, '10.66.')) {
remoteIp = req.get('X-Real-IP');
}
return _.trim(remoteIp);
};
module.exports = {
getClientIp,
};