【发布时间】:2019-12-19 05:08:44
【问题描述】:
您好,从过去一个月开始,我们的 Firebase 应用开始出现此错误。 “脚本资源位于重定向后面,这是不允许的。” 我们已经在服务器的根目录注册了 firebase-messaging-sw.js,它也在浏览器中打开。相同的代码在 localhost 中运行良好,但在公共域(cloudflare dNS)上会出现此错误
已经尝试过这里提到的解决方案:Firebase: change the location of the service worker
我们当前的代码:
messaging = firebase.messaging();
$this.setState({messaging});
messaging.useServiceWorker(registration);
messaging.requestPermission().then(function() {
$this.setState({permission:true});
messaging.getToken().then(function(currentToken) {
$this.setState({fcmtoken:currentToken});
resolve(currentToken);
});
});
});
firebase-messaging-sw.js 内容:
importScripts("https://www.gstatic.com/firebasejs/5.3.0/firebase-messaging.js");
var config = {
apiKey: "AIzxxxxxxxxxxxxxx0",
authDomain: "noxxxxions-7xxxd.firebaseapp.com",
databaseURL: "https://notifications-76xxxxd.firebaseio.com",
projectId: "nxxxxxxxxxxd",
storageBucket: "notifixxxxxx.appspot.com",
messagingSenderId: "90000000000"
};
firebase.initializeApp(config);
var messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
var notificationTitle = "Background Message Title";
var notificationOptions = {
body: "Background Message body.",
icon: "/firebase-logo.png"
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});```
【问题讨论】:
-
谁能帮我们解决这个问题?
标签: reactjs firebase firebase-cloud-messaging