【问题标题】:Unable to display website using Firebase Hosting无法使用 Firebase 托管显示网站
【发布时间】:2020-12-03 16:15:39
【问题描述】:

我正在尝试使用 Firebase 托管来托管我的动态 Node.js 网站,但根据我的文件结构,我遇到了困难。如下所示:

在我的代码中,我没有使用 index.html 文件,但是当我运行 firebase init 时,它会自动为我创建一个 404.html 文件。当我部署我的代码时,似乎只有 index.html 文件在执行。但是当我删除 index.html 文件后尝试部署时,我可以看到 404.html 文件。

这是 firebase.json 文件。我正在使用:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

“public/html”文件夹中的所有文件似乎都没有执行。我尝试在 firebase.json 文件中将公共字段更改为 public/html,但是部署时我只能看到Cannot GET / 。与 'src/js' 文件夹中的 js 文件一起部署时,如何运行 'public/html' 文件夹中的文件?

我的代码中有一个 error.html 文件,它位于“public/html/main”下。如果我想在404.html文件之外使用它,我必须直接放在公共文件夹中吗?

此外,我还有很多后端文件。为了使用这些,我是否需要使用 firebase 提供的其他服务,或者可以通过使用 Firebase Hosting 本身来完成?

【问题讨论】:

    标签: firebase firebase-hosting


    【解决方案1】:

    使用 Firebase 托管,如果您想在加载“/”路径时查看网页内容,则需要一个名为“index.html”的文件在您的公共目录中。它不会在子目录中查找。默认情况下,根据您显示的配置,所有路径都相对于公共提供。

    很难说出您期望的不同工作方式。如果你想引用嵌套在 html 下的 foo.html,那么你的路径需要是“/html/foo.html”。如果您想更改托管配置以做一些不同的事情,我建议您查看documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 2020-01-24
      相关资源
      最近更新 更多