首页 > 解决方案 > 脚本资源位于重定向后面,这是不允许的。firebase 云消息传递 firebase-messaing-sw.js

问题描述

这实际上是该主题的副本,因为没有人对此进行回复:脚本资源位于重定向后面,这是不允许的。firebase 云消息传递

嗨,从过去一个月开始,我们的 Firebase 应用程序开始出现此错误。“脚本资源位于重定向后面,这是不允许的。” 我们已经在服务器的根目录注册了 firebase-messaging-sw.js,它也在浏览器中打开。相同的代码在 localhost 中运行良好,但在公共域(cloudflare dNS)上出现此错误

https://prnt.sc/orot3j

已经尝试过这里提到的解决方案:Firebase:更改服务人员的位置

我们当前的代码:

                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);
    });```

标签: reactjsfirebasefirebase-cloud-messaging

解决方案


推荐阅读