Answer the question
In order to leave comments, you need to log in
How to send web push via localhost?
Good afternoon.
I'm trying to set up web pushes, I set everything up on FE, I send it through appspot and everything works. Now I wanted to send it myself via nodeJS using the library https://github.com/web-push-libs/web-push wrote the following code
const webpush = require('webpush');
// VAPID keys should only be generated only once.
const vapidKeys = webpush.generateVAPIDKeys();
webpush.setGCMAPIKey('');
webpush.setVapidDetails(
'mailto:[email protected]',
vapidKeys.publicKey,
vapidKeys.privateKey
);
// This is the same output of calling JSON.stringify on a PushSubscription
const pushSubscription = {
endpoint: '.....',
keys: {
auth: '.....',
p256dh: '..... '
}
};
webpush.sendNotification(pushSubscription, 'Your Push Payload Text').then(function (res) { .
console.log(res)
})
process.exit(1);
});
{ [WebPushError: Received unexpected response code]
name: 'WebPushError',
message: 'Received unexpected response code',
statusCode: 400,
}
Answer the question
In order to leave comments, you need to log in
checked for firefox everything works, but for chrome it writes an error
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question