push subscription has unsubscribed or expired, wit

2019-08-17 08:01发布

问题:

Push subscription has unsubscribed or expired, with statusCode 410, in less then 24 hours.

I'm using web-push to send notifications with fcm-endpoint & vapidDetails. It works fine for few hours, I can send notifications. But just after few hours saved-fcm-endpoint-subscription is getting unsubscribed or expired, with statusCode 410, when I try to send notification from the backend. I'm deploying & checking in Heroku.

The below code is to save subscription-object in the server/backend.

                  swReg.pushManager.subscribe({
                    userVisibleOnly: true,
                    applicationServerKey: urlB64ToUint8Array(publicKey),
                  }).then(subscriptionJSON => {
                    saveSubscription(subscriptionJSON);
                  })

After the above subscription-object saved in the server, it is getting expired just within few hours.

The Error looks like below:

{ 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:

There is a problem with ziet-server.

ziet-server stopped supporting write-access, i.e. fs.write won't work.

So i was not able to save/write subscription-objects into db-files.

I deployed into Heroku, now it's working as expected.