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 –