0

So I am now working a while with firebase, I have read some other topics, this does mean you must upgrade to a paid plan. However, locally I use http and it works fine. and on the server it does not work and throws: Error: getaddrinfo EAI_AGAIN site.com:443

I am not making an external request, the only thing I could think of is that it is external to Cloud functions and to Firebase hosting? Does that count as external? I am only calling/requesting pages on the Hosting side of Firebase. No external pages whatsoever.

What causes this error on the server, and what would be the recommended fix?

This codesample is from the Node.js of the cloud function:main.

var client = http;
client = (req.secure) ? https:client;
// console.log(client)

// const http = new XMLHttpRequest();
function httpRequest(params, postData) {
    return new Promise(function(resolve, reject) {
        console.log('params' + params)
        var req = client.request(params, function(res) {
            // reject on bad status
            if (res.statusCode < 200 || res.statusCode >= 300) {
                return reject(new Error('statusCode=' + res.statusCode));
            }
            // cumulate data
            var body = [];
            res.on('data', function(chunk) {
                body.push(chunk);
            });
            // resolve on end
            res.on('end', function() {
                try {
                    body = Buffer.concat(body).toString();
                } catch(e) {
                    reject(e);
                }
                resolve(body);
            });
        });
        // reject on request error
        req.on('error', function(err) {
            // This is not a "Second reject", just a different sort of failure
            reject(err);
        });
        if (postData) {
            req.write(postData);
        }
        // IMPORTANT
        req.end();
    });
}
zkohi
  • 2,486
  • 1
  • 10
  • 20
P. Hermens
  • 25
  • 7

1 Answers1

0

If you get this error:

Error: getaddrinfo EAI_AGAIN site.com:443

You are trying to access site.com from within your Cloud Functions code, which requires that your project is on a paid plan. Cloud Functions uses a (fairly simple) whitelist/regular expression to detect calls to Google APIs, and your web site's custom domain is definitely not going to be in that list.

If site.com is hosted on Firebase, you might want try accessing it through its projectid.firebaseapp.com alias, to see if that is whitelisted. If it isn't, you can always file a feature request for it to be added, but will only be able to call it on a paid plan for the time being.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Okay, I get that. I only think that isn't really clear from the documentation. I tried using the projectid and firebaseapp.com but that returned the same error. How would you recommend to use files from Hosting OR in the functions folder to get a internal html file and customize it before sending to the client? – P. Hermens May 19 '20 at 07:53
  • 1
    Okay I figured it out, using the function folder as the space for the used files. Then using the fs.readfile command. Was kind of easy. Thank you – P. Hermens May 19 '20 at 08:30