【发布时间】:2018-07-03 08:59:11
【问题描述】:
我正在尝试通过使用反向代理将 CORS 标头添加到请求中来从第三方 API (api.pubgtracker.com) 获取数据。
我的 index.js 看起来像这样:
const functions = require('firebase-functions');
const fetch = require('node-fetch')
exports.findPlayer = functions.https.onRequest((req, res) => {
let nickname = req.query.nickname;
let region = req.query.region;
let mode = req.query.mode;
let requestHeader = {
method: "GET",
headers: {
'my-api-key': 'value-of-my-api-key'
}
}
fetch(`https://cors-anywhere.herokuapp.com/https://api.pubgtracker.com/v2/profile/pc/${nickname}?region=${region}&mode=${mode}`, requestHeader)
.then(response => response)
.then(text => {
res.send(text);
});
});
问题是通过我的云功能,我得到的只是"Error: Could not handle the request",通过查看我看到的日志:
FetchError: request to https://cors-anywhere.herokuapp.com/https://api.pubgtracker.com/v2/profile/pc/VissGames?region=na&mode=solo-fpp failed, reason: getaddrinfo ENOTFOUND cors-anywhere.herokuapp.com cors-anywhere.herokuapp.com:443
这里有什么问题?在获取数据方面,我是一个纯粹的初学者,尽管我试图通过其他人针对类似问题提出的解决方案来解决问题,但我看不出哪里出了问题。
【问题讨论】:
-
尝试使用邮递员点击网址,您确定该网址吗?我可以在 url 中看到两个 https 块
标签: node.js cors fetch google-cloud-functions