Firebase Cloud functions express ip location

1,211 views
Skip to first unread message

renaud hedde

unread,
May 27, 2019, 1:00:30 PM5/27/19
to Google App Engine
Hi,

I'm working on cloud function projet with nodejs express

I'm trying to get the request user city location.

My request coming from france but every test I get the google US "mountain view" location....

I'm trying 3 differents technique to get ip
  • req.connection.remoteAddress
  • x-appengine-user-ip
  • x-forwarded-for
Also  I config express with app.set('trust proxy', true);

But anycase I got google server IP instead request user ip ?

many thanks

renaud

gjs

unread,
May 27, 2019, 11:20:36 PM5/27/19
to Google App Engine
Hi,

Try examining request headers eg

header X-AppEngine-Country = AU
header X-AppEngine-City = sydney

Regards

renaud hedde

unread,
May 28, 2019, 9:16:22 AM5/28/19
to Google App Engine
Ok,

After read cloud function request['header']

x-forwarded-for, fastly-client-ip display my ipAdress, good !

I test my ip with https://ipinfo.io and my city display, good as well ! 

However google cloud functions

X-AppEngine-Country is still US, bad :(

I don't understand why google don't use x-forwarded-for and/or not able to located my ip (maybe google IP database is not updated ?)

best regards 

renaud

Prashanth Acharya

unread,
May 28, 2019, 11:16:26 AM5/28/19
to google-a...@googlegroups.com
Cancel
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/a4e3891f-0e01-447c-882f-f40df0b13f2c%40googlegroups.com.

Sam (Google Cloud Support)

unread,
May 28, 2019, 5:42:35 PM5/28/19
to Google App Engine
Hi, as already noted, 'fastly-client-ip' is the header to use. According to this Stackoverflow post [1], the Firebase Cloud Functions docs points to using 'fastly-client-ip' [2]. 

Google Cloud Platform is a different platform for Cloud Functions which runs in App Engine, see this Stackoverflow post [3]. So if you are using a Firebase Cloud Function then using the 'x-forwarded-for' or 'fastly-client-ip' should be the headers to use.
Reply all
Reply to author
Forward
0 new messages