首页 > 解决方案 > 无法使用 Firebase 托管访问子目录中的任何文件

问题描述

我有一个托管在 Firebase Hosting 中的网站,当我从当前public文件夹加载内容时它工作正常。但我无法从像/img/logo.png.

我在这里和互联网上搜索过,但没有找到有效的解决方案。我试过一些类似的问题:

图片未显示在托管站点中

如何在 Firebase 托管中包含子目录


我的包括就像<script src="js/index.js"></script>

我的firebase.json

{
"database": {
 "rules": "database.rules.json"
},
"hosting": {
"public": "public",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"headers": [ {
  "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
  "headers" : [ {
    "key" : "Access-Control-Allow-Origin",
    "value" : "*"
} ]
}, {
  "source" : "**/*.@(jpg|jpeg|gif|png)",
  "headers" : [ {
  "key" : "Cache-Control",
  "value" : "max-age=7200"
  } ]
}, {
  "source" : "404.html",
  "headers" : [ {
  "key" : "Cache-Control",
  "value" : "max-age=300"
  } ]
} ]

}
}

标签: htmlfirebasefirebase-hosting

解决方案


firebase deploy通过在 Windows 上的 Ubuntu 上运行 Bash解决了这个问题。

以前,我在普通的 Windows 10 上使用 firebase cli。


推荐阅读