【问题标题】:Firebase Cloud Functions throws a DNS error when calling an external API [duplicate]Firebase Cloud Functions 在调用外部 API 时引发 DNS 错误 [重复]
【发布时间】:2018-07-18 17:08:39
【问题描述】:

我正在尝试调用 CoinMarketCap 的公共 API,但它总是失败并出现以下错误:

error occured Error: getaddrinfo ENOTFOUND api.coinmarketcap.com api.coinmarketcap.com:443

当我从浏览器调用 URL 时,它会立即返回结果。代码很简单:

const functions = require('firebase-functions');
const axios = require('axios');
exports.getBtcPrice = functions.https.onRequest((req, res) => {
    axios.get('https://api.coinmarketcap.com/v1/ticker/bitcoin')
        .then( (response) => {
            console.log(response);
            res.send("data received");
        })
        .catch((error) => {
            console.log(error);
            res.send("error occured "+ error)
        });
});

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    如果您使用的是具有 Firebase 功能的免费计划出站网络,则仅适用于 Google 服务。他们提到这是定价页面上的云功能部分https://firebase.google.com/pricing/

    如果您想使用第三方 API,则必须转到付费层。

    【讨论】:

      猜你喜欢
      • 2019-04-11
      • 2017-10-05
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 2020-05-10
      相关资源
      最近更新 更多