V
V
Vitaliy Semyanchuk2016-11-09 15:48:33
Node.js
Vitaliy Semyanchuk, 2016-11-09 15:48:33

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

and res keeps giving me this
{ [WebPushError: Received unexpected response code]
name: 'WebPushError',
message: 'Received unexpected response code',
statusCode: 400,
}

While I’m sinning on localhost, they say it can only be sent via https, well, there’s no way to check. Can anyone come across this and know how to solve the problem of sending pushes through localhost?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Semyanchuk, 2016-11-09
@fix20152

checked for firefox everything works, but for chrome it writes an error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question