Иво Стратев Иво Стратев - 6 months ago 26
Node.js Question

How to get real request client's ip from App Engine

I have set

app.set('trust_proxy', 1);
just like this page suggests
but for each request it gives the following ip address 169.254.160.2 ...

req.ip => 169.254.160.2
req.ips => [ '169.254.160.2' ]


Headers suggested headers are also with the same value ...
So how do I get the ip because all "what is my ip" sites tells me that my ip is 130.204.67.112

So how do i get my real ip in App Engine ?

ps. I'm using custom docker container for my app if that matters (I think it dosen't but still) I have migrated from heroku where it needs
app.enable('trust_proxy')
and it did work.

Answer

You can use the x-appengine-user-ip header directly:

var ip = req.headers['x-appengine-user-ip'];