【发布时间】:2019-10-15 12:13:10
【问题描述】:
推送订阅在不到 24 小时内取消订阅或过期,statusCode 410。
我正在使用 web-push 通过 fcm-endpoint 和 vapidDetails 发送通知。
它可以正常工作几个小时,我可以发送通知。但就在几个小时后,当我尝试从后端发送通知时,saved-fcm-endpoint-subscription 正在取消订阅或过期,statusCode 410。
我正在部署和检查 Heroku。
下面的代码是将订阅对象保存在服务器/后端。
swReg.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: urlB64ToUint8Array(publicKey),
}).then(subscriptionJSON => {
saveSubscription(subscriptionJSON);
})
上述订阅对象保存到服务器后,几小时内就过期了。
错误如下所示:
{ WebPushError: Received unexpected response code
at IncomingMessage.<anonymous> (/app/node_modules/web-push/src/web-push-lib.js:316:20)
at IncomingMessage.emit (events.js:194:15)
at endReadableNT (_stream_readable.js:1125:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'WebPushError',
message: 'Received unexpected response code',
statusCode: 410,
headers:
{ 'content-type': 'text/plain; charset=utf-8',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block',
date: 'Mon, 27 May 2019 10:11:38 GMT',
'content-length': '47',
'alt-svc': 'quic=":443"; ma=2592000; v="46,44,43,39"',
connection: 'close' }
【问题讨论】:
-
据我所知,410 表示订阅不再有效,应该从您的后端删除。这可以通过在
PushSubscription上调用unsubscribe()来复制。
标签: javascript push-notification service-worker progressive-web-apps web-push