【问题标题】:Firebase hosting static website not workingFirebase 托管静态网站无法正常工作
【发布时间】:2020-07-13 14:14:11
【问题描述】:

我正在尝试在 firebase 上托管一个静态网站。 (使用 macOS Catalina) 我用 npm 安装了 firebase CLI。 我网站的目录叫做 Knight 登录后,我运行以下命令:

firebase init

然后我选择了以下内容: 您要为此文件夹设置哪些 Firebase CLI 功能?

hosting

你想用什么作为你的公共目录?

public (I also tried dist and knight and Knight and KNIGHT)

配置为单页应用(将所有 url 重写为 /index.html)?

Y ( I also tried No )

文件 public/index.html 已经存在。覆盖?

N

然后初始化过程完成。 当我尝试firebase serve 并访问 http://localhost:5000 时,我得到了 firebase 欢迎页面。

如何查看我的网站?我是不是做错了什么?

我可以注意到,在我调用 firebase init 之后,firebase 没有在我的目录中写入任何文件。

【问题讨论】:

    标签: firebase firebase-hosting


    【解决方案1】:

    Firebase CLI 使用的过程非常简单:

    1. 您在特定目录中运行firebase init
    2. 回答“您想将什么用作公共目录?”关于您的index.html 和其他网络文件的路径的问题相对于您运行firebase.init 的目录

    既然你说你的网站在Knight,你应该回答“你想用什么作为你的公共目录?” Knight


    更新:您似乎在 index.html 文件所在的同一目录中运行 firebase init 命令。在这种情况下,您的“公共方向”是.,因为它与项目所在的目录相同。

    【讨论】:

    • 我试过了,这就是让我如此困惑的原因。它仍然提供相同的“欢迎页面”。我确信我选择了正确的目录,因为当我在 firebase 初始化过程中选择目录时,我可以看到在我的目录中创建了一个 .log 文件,其中有 index.html 文件。
    • 看起来index.html 在您运行firebase init 的目录中。我为我的答案添加了一个更新。
    【解决方案2】:

    好的,我发现了问题。在我的机器上搜索firebase.json 后,我意识到firebase 正在我的用户目录中写入文件,而不是在我调用firebase init 的地方写入它们。所以我到index.html 的路径如下:

    /Users/DCI/Documents/Knight/index.html
    

    但firebase正在将文件写入:

    /Users/DCI
    

    所以我要做的就是将Documents/Knight 作为firebase init 的公共目录。完成此操作后,我调用了 firebase serve 和 firebase deploy,它运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-21
      • 2017-04-30
      • 2019-12-12
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 2013-11-10
      相关资源
      最近更新 更多