Firebase函数 – getaddrinfo ENOTFOUND api.sandbox.paypal.com

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

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, ()=>{...})包装请求cors(req,res, ()=>{...})
  3. 预先https://到主机

问题是什么?

您需要使用付费计划来提出外部API请求。

Firebase的Blaze计划(按需付费)为Cloud Functions提供免费分配。 https://firebase.google.com/pricing/