0

我试图使用web-push node.js库向chrome浏览器发送推送通知。Node.js网络推送库

烧制

webpush.sendNotification(pushSubscription,payload) 

方法我得到这个响应之后 -

{ Error: unable to verify the first certificate 
at Error (native) 
at TLSSocket.<anonymous> (_tls_wrap.js:1060:38) 
at emitNone (events.js:86:13) 
at TLSSocket.emit (events.js:185:7) 
at TLSSocket._finishInit (_tls_wrap.js:584:8) 
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:416:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' } 

我猜这是一个SSL的问题?我该如何在本地主机上测试这个库?

谢谢

+0

[错误:无法验证的NodeJS第一证书]的可能的复制(http://stackoverflow.com/questions/31673587/error-unable-to-verify-the-first-certificate-in- nodejs) – Gimby

+0

你还能重现吗? –

+0

是的。这发生在使用http创建节点服务器时。 –

回答

0

我通过使用https和正确的键创建nodejs服务器来得到它的工作。

不知道这是否是正确的实施,但它为我们启动并运行。

const https = require('https'); 
const fs = require('fs'); 

const options = { 
    pfx: fs.readFileSync('server.pfx') 
}; 

https.createServer(options, (req, res) => { 
    //Do push things 
}).listen(443); 
+0

如果我诚实,这很奇怪。我不明白这会有什么帮助。你能否提供更多示例代码并在项目上打开一个问题:https://github.com/web-push-libs/web-push/issues/new –