Blocked because of disallowed mime type (“text/html”)

huangapple go评论67阅读模式
英文:

Blocked because of disallowed mime type ("text/html")

问题

我了解这个主题有很多问题,但在广泛查找后,我只找到一个Firebase示例,而且它没有涵盖我在使用托管时遇到的情况。

我正在测试的应用程序在Firebase托管中通过数据检索过程,第一页输入时数据正常进入。

当我刷新页面以测试我们使用的缓存是否正确检索数据时,整个应用程序变空白,并显示下面的错误。

在查看是否已经提出类似问题的示例时,我发现控制台中的错误并不一定指向实际问题,这使得一切变得更加令人困惑。为了帮助读者,我将包含vite和firebase配置文件,以显示项目连接正常。我还将在我的dist文件夹中添加index.html,以显示错误中提到的.js文件。

Blocked because of disallowed mime type (“text/html”)

Blocked because of disallowed mime type (“text/html”)

Blocked because of disallowed mime type (“text/html”)

Blocked because of disallowed mime type (“text/html”)

在检查后端的云函数时,我注意到检索详细信息的函数仅在第一次成功加载时执行。当我刷新时,它不会再次执行,这使我认为可能与路由有关,但我还没有弄清楚那里的问题可能是什么,除了传递的docId作为prop不可用之外。

我能够在不将docId作为prop传递的任何页面上刷新,但我感到困惑的一点是我无法复制本地主机上得到的错误。在那里,我可以随时刷新而没有任何问题。这里的问题是什么?我正在使用Vue 3与Vite和Firebase。

英文:

I am aware there are many questions regarding this topic, but after extensive looking there was only one Firebase example and it didn't cover my scenario with using hosting.

I have an app that I am currently testing in Firebase hosting, the app goes through the data retrieval process well enough with data coming in fine on first page entry.

When I go to refresh the page in order to test that the cache we are using retrieves the data properly, the entire app goes blank and I receive the errors shown below

After some looking into if similar example have already been asked, I found out that the errors in the console dont necessarily point to the actual issue, making this all the more confusing. In order to help the reader I will include the vite and firebase config files to show the project is connected fine. I will also add the index.html in my dist folder to show the .js file mentioned in the error.

Blocked because of disallowed mime type (“text/html”)

Blocked because of disallowed mime type (“text/html”)

Blocked because of disallowed mime type (“text/html”)

Blocked because of disallowed mime type (“text/html”)

One thing I did notice while checking my cloud functions on the backend is that the function that retrieves the detail information is only hit once on the first successful load. When I refresh, it doesn't get hit again, which gives me the idea it may be something related to the router, but I haven't worked out what the issue there might be besides the docId that's passed as a prop not being available.

I am able to refresh any page where I don't pass the docId as a prop as well, but some confusion I have is I'm not able to replicate the error I'm getting on localhost. There, I am able to refresh fine anywhere without issues at all. Any idea what the problem here is? I am using Vue 3 with Vite and Firebase.

答案1

得分: 1

问题出在你的"rewrites",这导致每个路由都被提供为index.html。然后,由于FireFox默认为nosniff,因此当你的资源都具有text/html的内容类型时,它会失败。

在你的特定情况下,访问/assets/index.659db071.js,然后按CTRL+U查看源代码。注意它是你的index.html文件,而不是应该的JavaScript文件。

英文:

The problem here is your "rewrites", which causes every route to be served index.html. Then since FireFox is nosniff by default, it fails when your resources all have content type text/html.

In your specific case, visit /assets/index.659db071.js and press CTRL+u to view source. Notice it's your index.html file and not the JavaScript it should be.

答案2

得分: 1

As covered by @BrownieInMotion's answer, your rewrite rule for "source": "**" is redirecting all non-existent files to your main /index.html file. Because ./assets/index.659db071.js does not exist on your deployed app (at time of writing, the current version is ./assets/index.2b83c04b.js), the browser gets sent the content of /index.html instead (a text/html file). This causes the error you are seeing.

To correct your rewrite rule, so that it doesn't redirect for anything in the /assets folder, you should update your firebase.json file to the following:

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**",
    ],
    "rewrites": [
      {
        "source": "!/@(assets|images)/**",
        "destination": "/index.html"
      }
    ]
  }
}

Here any file in the "assets" (make sure its the same as build.assetsDir) or "images" (included to show how to specify multiple folders) folders won't be redirected to /index.html and will instead be shown your configured 404 error page.

Additionally, your index.html should probably be updated to refer to /assets/index.****.js instead (note missing . at the start) so that it always refers to https://example.com/assets/index.****.js instead of improperly handling nested paths such as https://example.com/renter-team-profile/assets/index.****.js in your error in the question. Unfortunately, I'm not familiar enough with Vite to know where the setting for this is.

英文:

As covered by @BrownieInMotion's answer, your rewrite rule for "source": "**" is redirecting all non-existent files to your main /index.html file. Because ./assets/index.659db071.js does not exist on your deployed app (at time of writing, the current version is ./assets/index.2b83c04b.js), the browser gets sent the content of /index.html instead (a text/html file). This causes the error you are seeing.

To correct your rewrite rule, so that it doesn't redirect for anything in the /assets folder, you should update your firebase.json file to the following:

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**",
    ],
    "rewrites": [
      {
        "source": "!/@(assets|images)/**",
        "destination": "/index.html"
      }
    ]
  }
}

Here any file in the "assets" (make sure its the same as build.assetsDir) or "images" (included to show how to specify multiple folders) folders won't be redirected to /index.html and will instead be shown your configured 404 error page.


Additionally, your index.html should probably be updated to refer to /assets/index.****.js instead (note missing . at the start) so that it always refers to https://example.com/assets/index.****.js instead of improperly handling nested paths such as https://example.com/renter-team-profile/assets/index.****.js in your error in the question. Unfortunately, I'm not familiar enough with Vite to know where the setting for this is.

huangapple
  • 本文由 发表于 2023年5月22日 05:08:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定