Not All Headers Are Shown With Firebase OnRequest
I'm trying to learn Firebase while making a small project, where I need to store IP addresses in my system.
But I realized that it's not working like I'm used to work with Express. I need the exact same result of this Gist: https://gist.github.com/katowulf/6fffffb45ee5cbfbca6c3511e5d19528#gistcomment-2674393
However doing the same things doesn't work for me, I don't get so many headers and also not getting the client IP address.
exports.getPolls = functions.region('europe-west1').https.onRequest((req, res) => {
console.log(util.format(req.headers))
});
Header's I get
headers:
{ host: 'localhost:5001',
connection: 'keep-alive',
'upgrade-insecure-requests': '1',
'user-agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3370.152 Safari/537.36',
accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en,nl;q=0.9,tr;q=0.8',
cookie: 'io=AVNO7ouAHOYCkVK8ADSD',
'if-none-match': 'W/"5-qvTGHdzV6LKavt4PO0gs2a6pQ00"'
},
I need the client IP address
Answer
This problem has been solved: https://github.com/firebase/firebase-functions/issues/541
Short explanation:
when doing firebase serve
the request headers are coming from an emulator which has not the expected headers, firebase deploy
is what you need to do.
Going to the firebase console
> functions (choose your function) > logs, would show the expected headers (with the x-forwarded-for
header) when you console log like me.
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error