简体   繁体   English

FCM推送通知在本地有效,但在服务器上无效

[英]FCM Push notifications works locally but not on server

I have been struggling to make push notifications work. 我一直在努力使推送通知起作用。 I am recieving the following error 我收到以下错误

; ; FirebaseError: Messaging: We are unable to register the default service worker. FirebaseError:消息传递:我们无法注册默认服务工作者。 Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. 无法注册ServiceWorker:获取脚本时收到错误的HTTP响应代码(404)。 (messaging/failed-serviceworker-registration). (消息/失败-serviceworker注册)。

I have already tried to google and applied https://stackoverflow.com/a/42264578/5192105 我已经尝试过Google并应用了https://stackoverflow.com/a/42264578/5192105

But still it works locally but not on the server . 但是它仍然可以在本地运行,但不能在服务器上运行 The js file firebase-messaging-sw.js exists in the path: https://mobile-app.golocall.com/api/src/public/firebase-messaging-sw.js 路径中存在js文件firebase-messaging-sw.jshttpsfirebase-messaging-sw.js

I have used slim-php as backend framework. 我使用了slim-php作为后端框架。

Please help me out in resolving the error. 请帮助我解决错误。

It tries to find the service worker file on the root of the application; 它尝试在应用程序的根目录中找到服务工作者文件; hence the application tries to load 因此,应用程序尝试加载

https://mobile-app.golocall.com/firebase-messaging-sw.js https://mobile-app.golocall.com/firebase-messaging-sw.js

while the actual file is located at 而实际文件位于

https://mobile-app.golocall.com/api/src/public/firebase-messaging-sw.js https://mobile-app.golocall.com/api/src/public/firebase-messaging-sw.js

EDIT: 编辑:
You may be able to import the service worker like this: 您可以像这样导入服务工作者:

importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');

If this doesn't work, you may need to declare your own service worker. 如果这不起作用,则可能需要声明您自己的服务工作者。

Here is a link to more information on the topic: 这是有关该主题的更多信息的链接:
https://firebase.google.com/docs/cloud-messaging/js/receive https://firebase.google.com/docs/cloud-messaging/js/receive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果浏览器在后台,FCM 推送通知会到达两次 - FCM Push notifications arrive twice if the browser is in background 如何使用带有FCM的服务工作者进行推送通知 - How to use service worker with FCM for Push Notifications 如何在网站旁边设置 FCM 应用服务器以发送推送通知? - How to set up a FCM app server alongside a website to send push notifications? 在服务器上推送通知的问题 - Problems with Push Notifications on Server Javascript 在本地工作,但不在服务器上 - Javascript works locally but not on the server 如何在 nuxtjs / vuejs 上实现 Firebase(FCM) 推送通知 - How to implement Firebase(FCM) Push Notifications on nuxtjs / vuejs 通过 FCM 同时收到两条相同的消息作为推送通知 - Two identical messages are received at the same time as push notifications through FCM 对话推送通知中的 Twilio“GCM/FCM 未授权错误:GCM/FCM API 密钥已撤销或无效” - Twilio "GCM/FCM unauthorized error: GCM/FCM API key is revoked or invalid" in conversations push notifications '=='在本地工作,但在服务器上进行比较需要'=' - '==' works locally but '=' required for comparison on server Javascript可在本地使用,但不能在带有niceEdit的服务器上使用 - Javascript works locally but not on server with niceEdit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM