推送订阅已取消订阅或已过期,状态码为410

时间:2019-05-29 20:29:43

标签: javascript push-notification service-worker progressive-web-apps web-push

在不到24小时的时间内,statusCode 410的订阅已取消订阅或过期。

我正在使用网络推送功能通过fcm-endpoint和vapidDetails发送通知。 它可以正常工作几个小时,我可以发送通知。但是仅在几个小时后,当我尝试从后端发送通知时,保存的-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' } 

1 个答案:

答案 0 :(得分:0)

ziet-server 有问题。

ziet-server 不再支持写访问,即fs.write将不起作用。

所以我无法将订阅对象保存/写入到db文件中。

我部署到了 Heroku ,现在它可以正常工作了。

相关问题