[英]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.js
: https : firebase-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.