Firebase 云函数 - getaddrinfo ENOTFOUND [英] Cloud Functions for Firebase - getaddrinfo ENOTFOUND

查看:37
本文介绍了Firebase 云函数 - getaddrinfo ENOTFOUND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 PayPal-node-SDK 向 Paypal 的 API 发出请求>

Trying to make a request to Paypal's API using PayPal-node-SDK

exports.requestPayment = functions.https.onRequest((req, res) => {
    return new Promise(function (fullfilled, rejected) {
        paypal.payment.create(create_payment_json, {}, function (error, payment) {
            if (error) {
                rejected(error);
            } else {
                console.log("Create Payment Response");
                console.log(payment);
                res.status(200).send(JSON.stringify({
                    paymentID: payment.id
                })).end();
                fullfilled(payment);
            }
        });
     });
});

但我不断收到错误:

Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

我尝试过的事情:

  1. 向完全不同的主机发出请求,仍然ENOTFOUND
  2. 使用 cors(req,res, ()=>{...})
  3. 包装请求
  4. https:// 附加到主机
  1. Making a request to a totally different host, still ENOTFOUND
  2. Wrapping the request with cors(req,res, ()=>{...})
  3. Prepending https:// to the host

有什么问题?

推荐答案

您需要使用付费计划才能发出外部 API 请求.

You'll need to be on a paid plan to make external API requests.

Firebase 的 Blaze 计划(即付即用)为 Cloud Functions 提供免费配额.https://firebase.google.com/pricing/

Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/

这篇关于Firebase 云函数 - getaddrinfo ENOTFOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆