节点js获取请求IP不返回任何内容

时间:2021-07-06 07:36:26

标签: node.js request ip

我有一个节点 js 服务器。我有获取请求 IP 的功能:

    var ip = request.headers['x-forwarded-for'] ||
        request.connection.remoteAddress ||
        request.socket.remoteAddress ||
        request.connection.socket.remoteAddress;
    ip = ip.split(',')[0];
    ip = ip.split(':').slice(-1);
    return ip;
}```

But when I console.log(getCallerIP(request)); 
That send me sometimes in log : [ 'MYIP' ] and sometimes nothing.
Why ? And how to fix that ? ( in the server or the client ) 

0 个答案:

没有答案
相关问题