我创建了一个基本的应用程序,尝试使用 web-push 节点库发送推送通知。\n但是,我总是遇到错误:“你必须至少传入一个端点”\n我不明白,因为我“subscribe”(使用 ServiceWorker Api subscribe() 方法),它创建一个到我的本地主机地址的端点
\n\n事实上,我真的不知道该怎么做才能解决这个问题
\n\n这是我的“订阅”代码:
\n\nasync subscribe() {\n const sw = await navigator.serviceWorker.ready; \n const applicationServerPublicKey = \'BADCyHKPTCj1B9Knvmz2_EF1iLieHVZX2eEcCnMLvmMJA2ADlcDILgDC31ztGp1T1TznLpaJ14GQbdIM4APrr6k\';\n const applicationServerKey = this.urlB64ToUint8Array(applicationServerPublicKey);\n console.log("le service worker est " + sw);\n sw.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: applicationServerKey,\n }).then(\n subscription => {\n console.log("User is subscribed with the subscription : ");\n console.log(subscription);\n
Run Code Online (Sandbox Code Playgroud)\n\n在控制台上,我可以看到在“订阅”对象中有一个端点\n这里是发送通知的代码:
\n\nconsole.log("Juste avant d\'envoyer la notif on veut envoyer \xc3\xa0 :")\nconsole.log(this.state.endpoint)\n\nwebpush.sendNotification(\n this.state.endpoint,\n payload,\n options\n);\n
Run Code Online (Sandbox Code Playgroud)\n\n但我进入控制台:
\n\n\nJuste avant d\'envoyer la notif on …