Monday 29 May 2017

Help! Node can't get the user's IP address

HelloI hope someone can help me with this!I have a piece of JS on a website. It does a XHR to post some data to a node app:var xhr = typeof XMLHttpRequest === "undefined" ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest; xhr.open("POST", 'https://myserver', true); xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhr.send(JSON.stringify(data)); And in the node app it tries to grab the user's IP address through either req.headers['x-forwarded-for'] or req.connection.remoteAddress or req.socket.remoteAddress or req.ip, but I always end up with something like undefined or ::ffff:127.0.0.1.Do you have any ideas what could be causing this?Thank you.

Submitted May 29, 2017 at 05:31PM by just_tech_stuff

No comments:

Post a Comment