lavas-project/pwa-doc

反馈:engage-retain-users/how-push-works.md

Closed this issue · 2 comments

//使用 webpush.sendNotification 发起通知,报下面错误:
{ Error: read ECONNRESET
at exports._errnoException (util.js:1022:11)
at TLSWrap.onread (net.js:569:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

开了翻墙,服务器为express,代码如下,为本地开发localhost访问环境,没有https,请问有办法处理吗?

//之前保存的pushSubscription
let pushSubscription = JSON.parse(fs.readFileSync('pushSubscription.txt'));

var body = '谢谢关注';
var iconUrl = 'http://localhost:8087/images/huiju.png';

webpush.sendNotification(pushSubscription,
JSON.stringify({
msg: body,
url: 'http://localhost:8087',
icon: iconUrl,
type: 'register'
}))
.then(result => {
console.log(result);
res.send({status:0,mes:"发送成功"});
})
.catch(err => {
console.log(err);
});

localhost 也可以用来本地测试的,只有上线才需要 https
我尝试一下你的代码,之后给你结论~

这个问题我们已经有同事给 web-push 类库提了问题了,你可以关注那边的进展(目前看好像也没进展的样子……)

链接在此 web-push-libs/web-push#320