【问题标题】:Cloud functions - could not handle the request云功能 - 无法处理请求
【发布时间】: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


【解决方案1】:

我检查了https://cors-anywhere.herokuapp.com/ 是否工作。您的应用程序正在为cors-anywhere.herokuapp.com:443 抱怨ENOTFOUND。这意味着它无法访问https://cors-anywhere.herokuapp.com/。这意味着它没有正确的网络连接或有problem with your DNS

如果您提供更多数据,可以提供更多帮助。 (例如:尝试访问其他 URL,例如 google.com)

【讨论】:

  • 是的,这意味着您的节点应用程序无法访问 Internet。你的操作系统是什么?可能是防火墙阻止了您?
  • 我正在使用 Windows 10。我的防火墙也允许使用 node.js。
  • 你怎么知道的?关闭防火墙 10 秒并运行程序
  • 是的,还是什么都没有。
猜你喜欢
  • 1970-01-01
  • 2018-01-17
  • 2021-12-17
  • 1970-01-01
  • 2018-04-13
  • 2019-01-31
  • 1970-01-01
  • 2019-06-09
  • 2020-07-18
相关资源
最近更新 更多