3

我正在尝试设置一个使用 Express 并发出 HTTP 请求的函数,但无论我发出什么请求,我总是会收到 ENOTFOUND 错误。

我已经尝试使用 4 个不同的库(https、request、request-promise、requestify)发出请求,但都给出了相同的错误。

我按照以下示例设置系统:minimum-webhook + authorized-https-endpoint


我的基本测试功能,也会引发错误:

"use strict";
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);

const express = require("express");
const app = express();

const https = require("https");

app.get("*", (req, res) =>
{
    var testReq = https.request({
        host: "www.google.com",
        path: "/recaptcha/api/siteverify"
    },

    (res) => {
        console.log("Finished with response " + res);
    });

    testReq.on("error", (e) => {
        console.log("Crashed with error " + e);
    });

    testReq.end();
});

exports.test = functions.https.onRequest(app);

使用 Postman的 GET 请求日志https://us-central1-project-abc.cloudfunctions.net/test/,例如:

Crashed with error Error: getaddrinfo ENOTFOUND www.google.com www.google.com:443
4

2 回答 2

4

ENOTFOUND错误getaddrinfo意味着您的 DNS 解析器找不到 DNS 地址。也许您需要使用代理或不同的 DNS 解析器。确保您的 Firebase 功能完全可以建立出站互联网连接。

于 2017-03-17T12:04:37.743 回答
3

实际上,您只需要参加付费计划就可以提出外部请求。

Blaze 计划(即用即付)可能对您有好处(我目前正在使用该计划,零费用)。

https://firebase.google.com/pricing/

于 2017-07-04T04:21:57.423 回答