I'm trying to follow Google's Web Push tutorial: https://developers.google.com/web/fundamentals/push-notifications/sending-messages-with-web-push-libraries
I have the node server set up with the ability to receive subscriptions. What I'm unsure about is how to send a subscription request from the client-side?
The tutorial only shows you how to make a post request, but what the hell is the payload you're actually sending? What is the endpoint that the server is checking for? This is not in the tutorial.
function sendSubscriptionToBackEnd(subscription) {
return fetch('/api/save-subscription/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(subscription)
})
.then(function(response) {
if (!response.ok) {
throw new Error('Bad status code from server.');
}
return response.json();
})
.then(function(responseData) {
if (!(responseData.data && responseData.data.success)) {
throw new Error('Bad response from server.');
}
});
}
So when I do
sendSubscriptionToBackEnd(subscription)
What is subscription
supposed to look like?