【发布时间】:2019-11-27 23:00:49
【问题描述】:
我在做一个小项目时尝试学习 Firebase,我需要在我的系统中存储 IP 地址。
但我意识到它不像我以前使用 Express 那样工作。 我需要这个 Gist 的完全相同的结果:https://gist.github.com/katowulf/6fffffb45ee5cbfbca6c3511e5d19528#gistcomment-2674393
但是做同样的事情对我不起作用,我没有得到这么多的标头,也没有得到客户端 IP 地址。
exports.getPolls = functions.region('europe-west1').https.onRequest((req, res) => {
console.log(util.format(req.headers))
});
我得到的标题
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"'
},
我需要客户端 IP 地址
【问题讨论】:
-
什么是
console.log(req.headers)和console.log(req.headers['fastly-client-ip'])打印出来的? -
@Nathan
console.log(req.headers)只是打印我在“我得到的标题”上面提到的内容。console.log(req.headers['fastly-client-ip'])打印出undefined
标签: node.js firebase express google-cloud-firestore google-cloud-functions