脚本资源位于重定向之后,这是不允许的。 firebase云消息传递firebase-messaing-sw.js

时间:2019-08-22 14:36:32

标签: reactjs firebase firebase-cloud-messaging

这实际上是该主题的重复,因为没有人对此进行回复:The script resource is behind a redirect, which is disallowed. firebase cloud messaging

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

https://prnt.sc/orot3j

这里已经提到了已经尝试过的解决方案: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);
    });```

0 个答案:

没有答案