Firebase FCM获取错误的HTTP响应代码(404)

Firebase FCM获取错误的HTTP响应代码(404),firebase,google-cloud-messaging,cloud,firebase-cloud-messaging,Firebase,Google Cloud Messaging,Cloud,Firebase Cloud Messaging,我尝试在我的网站上使用fcm,为此我使用本教程: 为此,我在索引文件中添加了以下代码: <script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"></script> <script> // Initialize Firebase // TODO: Replace with your project's customized code snippet var config =

我尝试在我的网站上使用fcm,为此我使用本教程:

为此,我在索引文件中添加了以下代码:

<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"></script>
<script>
  // Initialize Firebase
  // TODO: Replace with your project's customized code snippet
  var config = {
    apiKey: "mykey",
    authDomain: "<PROJECT_ID>.firebaseapp.com",
    databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
    projectId: "kyochat-ea3f6",
    storageBucket: "<BUCKET>.appspot.com",
    messagingSenderId: "sender_id",
  };
//   firebase.initializeApp(config);
firebase.initializeApp(config);

const messaging = firebase.messaging();

messaging.requestPermission()
  .then(function(e=null) {
      console.log("Granted!"+e);
      return messaging.getToken()
          .then(function(token) {
                console.log(token);
          }).catch(function(err) {
                console.log("Error! :: "+err);
          });
  })
</script>
此文件为空。我正在使用apache服务器调用此文件

但我得到了这个错误:

 Error! :: FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).

我在互联网上搜索时,每个人都说我需要将这个文件firebase-messaging-sw.js放在我的根目录中。

你读过你引用的文件吗?“FCM SDK仅在通过HTTPS提供的页面中受支持。这是因为它使用了服务工作者,而服务工作者仅在HTTPS站点上可用。需要提供商吗?Firebase托管是在您自己的域上获得免费HTTPS托管的一种简单方法。”我不知道该文档,但我找到了解决方案firebase-messaging-sw.js。该文件需要进行某种初始化。@NilaySingh您解决了这个问题吗?我也陷入了同样的问题
 Error! :: FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).