/**
@getClientIP
@desc 获取用户 ip 地址
@param {Object} req - 请求
*/
function getClientIP(req) {
    return req.headers['x-forwarded-for'] || // 判断是否有反向代理 IP
    req.connection.remoteAddress || // 判断 connection 的远程 IP
    req.socket.remoteAddress || // 判断后端的 socket 的 IP
    req.connection.socket.remoteAddress;
};
1
2
3
4
5
6
7
8
9
10
11
Last Updated: 9/14/2020, 12:20:49 PM