Messaging API not using http.Agent (proxy)
Describe your environment
Operating System version: Windows 10 Firebase SDK version: 8.8.0 Firebase Product: Messaging Node.js version: v10.15.1 NPM version: 6.4.1
Describe the problem
When using the Messaging API the request do not utilize the setted http.Agent when application was initialized. This results in the requests to fail if sending behind a proxy with the following error:
Error while making request: getaddrinfo ENOTFOUND fcm.googleapis.com fcm.googleapis.com:443. Error code: ENOTFOUND
The authentication does work as it is using the http.Agent properly when passed to:
var firebaseadmin = require("firebase-admin");
firebaseadmin.initializeApp({
credential: firebaseadmin.credential.cert(accountKey, new HttpsProxyAgent(process.env.http_proxy))
});
Steps to reproduce:
You have to be making request through a proxy server.
Ugly fix
Ugly fix is to modify messaging-api-request.js
var HttpsProxyAgent = require('https-proxy-agent');
and then adding httpAgent to all the requests, e.g.:
FirebaseMessagingRequestHandler.prototype.invokeRequestHandler = function (host, path, requestData) {
var request = {
method: FIREBASE_MESSAGING_HTTP_METHOD,
url: "https://" + host + path,
data: requestData,
headers: LEGACY_FIREBASE_MESSAGING_HEADERS,
timeout: FIREBASE_MESSAGING_TIMEOUT,
httpAgent: new HttpsProxyAgent(process.env.http_proxy)
};
...
}
AuthorizedHttpClient automatically adds the httpAgent to all requests:
https://github.com/firebase/firebase-admin-node/blob/45905e4558afff6c7b0cc5e7b1ce73c9e1f51950/src/utils/api-request.ts#L819-L821
Here's the corresponding test case:
https://github.com/firebase/firebase-admin-node/blob/45905e4558afff6c7b0cc5e7b1ce73c9e1f51950/test/unit/utils/api-request.spec.ts#L1261-L1280
Problem here is you don't have an httpAgent specified in AppOptions. You're only specifying it for the credential, which is not enough.
Thank you hiranya911. You are correct. It is working when the httpAgent was also set in the AppOptions.