web-push-libs / web-push

Web Push library for Node.js
Other
3.21k stars 306 forks source link

getaddrinfo ENOTFOUND fcm.googleapis.com fcm.googleapis.com:443 #329

Closed GeorgeTailor closed 6 years ago

GeorgeTailor commented 6 years ago

Setup

Operating System: <macOS High Sierra 10.13.1> Node Version: <8.6.0> web-push Version: <3.3.1>

Please select any browsers that you are experiencing problems with:

Chrome 66

Problem

When sending request to endpoint which should send the notification the following error is thrown:

Error: getaddrinfo ENOTFOUND fcm.googleapis.com fcm.googleapis.com:443

Expected

webpush.sendNotification(subscription, dataToSend) should send push msg instead of throwing error.

Features Used

Example / Reproduce Case

Please provide a code sample that reproduces the issue. If there is a repository that reproduces the issue please put the link here.

relevant code goes as follows:

app.post('/api/trigger-push-msg/', function (req, res, next) {
    const notification = {
        "notification": {
          "title": "Yuriy Kravets",
          "body": 'Yay it works.'
        }
    };

    return triggerPushMsg(sub.subscription, notification.toString()).then(() => {
        res.setHeader('Content-Type', 'application/json');
        res.send(JSON.stringify({ data: { success: true } }));
    });
});

const triggerPushMsg = function(subscription, dataToSend) {
    return webpush.sendNotification(subscription, dataToSend)
    .catch((err) => {
        if (err.statusCode === 410) {
            console.log('delete');
            // return deleteSubscriptionFromDatabase(subscription._id);
        } else {
            console.log('Subscription is no longer valid: ', err);
        }
    });
};

Other

Subscription is valid and is saved locally as variable in the node.js express instance.

I am using angular ngsw for service worker setup, which handles most of the dirty work. Also, I've checked the endpoint returned by ngsw and it seems legit. It has the following format: https://fcm.googleapis.com/fcm/send/cshk3UHgWLw:APA91bGuj3kA619Gr_pgUiCUI55tTQrpXW22PR_vZA0oRr-VS4BaxHGiX8o4gEha42FDNzGbMWKiDQlcHVca7DFoGHeaVQOwtHJcVXmjZJuAHDQihDeCV4_r7iIf47nyIs1-ozkiHQ10

GeorgeTailor commented 6 years ago

Consider extending readme to include that the options object can accept proxy object with proxy config. This issue was resolved when I've added proxy config.

marco-c commented 6 years ago

https://github.com/web-push-libs/web-push/pull/330 is adding the docs.

jaya-nanden commented 2 years ago

I am also facing the same issue.