3

I'm trying to set up a function that uses Express and makes HTTP requests, but I always get an ENOTFOUND error, no matter the request I make.

I already tried making the requests using 4 different libraries (https, request, request-promise, requestify), but all give the same error.

I followed this examples to set up the system: minimal-webhook + authorized-https-endpoint.


My basic test function, that also throws the error:

"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);

Log of GET request to https://us-central1-project-abc.cloudfunctions.net/test/ using Postman, for example:

Crashed with error Error: getaddrinfo ENOTFOUND www.google.com www.google.com:443
Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Sergio Carneiro
  • 3,402
  • 3
  • 32
  • 50

2 Answers2

4

The ENOTFOUND error for getaddrinfo means that your DNS resolver cannot find the DNS address. Maybe you need to use a proxy or a different DNS resolver. Make sure that your Firebase function can make outbound internet connections at all.

rsp
  • 91,898
  • 19
  • 176
  • 156
  • 3
    `Outbound connections`... Following that thought, I would say it's a problem with my free plan. Firebase says it "only allows outbound network requests to Google owned services". But I'm making a request to a google service, no? – Sergio Carneiro Mar 17 '17 at 12:19
  • 1
    I got the same problem. Maybe need to upgrade the plan – John Apr 25 '17 at 03:18
  • @John. Did you solve problem? Upgrade the plan? – HuyLe Apr 05 '18 at 01:57
  • 1
    Isn't firebase google service? Also even with Google Identity Rest calls, i see the same issue as mentioned. Wondering why its happening even if it's a google service. – Ayyappa Apr 20 '18 at 05:03
3

Actually you just need to be on a paid plan to be able to make external requests.

The Blaze plan (pay as you go) can be good for you (I'm currently using that plan with zero charges).

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

isijara
  • 135
  • 2
  • 9