I trying to get current web address using sails.js.
I tried the following:
req.param(\'host\') and req.param(\'X-Forwarded-Protocol\')
I have tried some examples I have found in google but nothing seemed to work at least in my local machine.
Using this in my local machine returned:
req.ip; --> ::1
Using this in my local machine returned:
req.headers['x-forwarded-for']; --> undefined
Finally, using this in my local machine returned:
var paramIp = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress; --> ::1
Nothing seemed to work. Then I tried in production environment
and the first example returned:
req.ip; --> ::ffff:10.155.43.243
It seems to be working but as you can see it is an IPv6 ip address so that's not what I wanted.
And the example number 3 returned:
187.214.247.196
So that's excellent because that's what I needed.
All I have to said is that the example number 3 worked fine but just in production environment (using Heroku) not for development in my local machine.