我正在尝试遵循Google的Web推送教程:https://developers.google.com/web/fundamentals/push-notifications/sending-messages-with-web-push-libraries
我已将节点服务器设置为可以接收订阅。我不确定如何从客户端发送订阅请求?
本教程仅向您显示如何发出发布请求,但是您实际发送的有效负载到底是什么呢?服务器正在检查的端点是什么?这不在教程中。
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.');
}
});
}
所以当我这样做
sendSubscriptionToBackEnd(subscription)
subscription
应该是什么样子?