[英]Firebase hosting static website not working
I am trying to host a static website on firebase.我正在尝试在 firebase 上托管 static 网站。 ( using macOS Catalina ) I installed firebase CLI with npm.
(使用 macOS Catalina)我用 npm 安装了 firebase CLI。 The directory of my website is called Knight After logging in, I run this command:
我网站的目录名为 Knight 登录后,我运行以下命令:
firebase init
Then I chose the following: Which Firebase CLI features do you want to set up for this folder?然后我选择了以下内容:您要为此文件夹设置哪些 Firebase CLI 功能?
hosting
What do you want to use as your public directory?你想用什么作为你的公共目录?
public (I also tried dist and knight and Knight and KNIGHT)
Configure as a single-page app (rewrite all urls to /index.html)?配置为单页应用(将所有 url 重写为 /index.html)?
Y ( I also tried No )
File public/index.html already exists.文件 public/index.html 已经存在。 Overwrite?
覆盖?
N
Then the init process is done.然后初始化过程就完成了。 When I try
firebase serve
and I got to http://localhost:5000 I get the firebase welcome page.当我尝试
firebase serve
并到达 http://localhost:5000 时,我得到了 firebase 欢迎页面。
How can I see my website?如何查看我的网站? Did I do something wrong?
我做错什么了吗?
I can notice that firebase is not writing any files in my directory after I call firebase init.我注意到 firebase 在我调用 firebase init 后没有在我的目录中写入任何文件。
The process that the Firebase CLI uses is pretty straightforward: Firebase CLI 使用的过程非常简单:
firebase init
in a specific directoryfirebase init
index.html
and other web files relative to the directory where you run firebase.init
index.html
和其他 web 文件相对于您运行firebase.init
的目录的路径的问题Since you say that you have you web site in Knight
, you should answer "What do you want to use as your public directory?"既然你说你在
Knight
有你的 web 站点,你应该回答“你想用什么作为你的公共目录?” with Knight
.与
Knight
。
Update : It seems that you are running the firebase init
command in the same directory where your index.html
file is.更新:您似乎在
index.html
文件所在的同一目录中运行firebase init
命令。 In that case your "public direction" is .
在这种情况下,您的“公共方向”是
.
, since it's the same directory that the project is in. ,因为它与项目所在的目录相同。
Ok, I found the problem.好的,我发现了问题。 After searching for
firebase.json
on my machine I realized that firebase was writing the files in my user directory, instead of writing them where I called firebase init. After searching for
firebase.json
on my machine I realized that firebase was writing the files in my user directory, instead of writing them where I called firebase init. So my path to index.html
would look like:所以我的
index.html
路径看起来像:
/Users/DCI/Documents/Knight/index.html
But firebase is writing the files in:但是 firebase 正在将文件写入:
/Users/DCI
So what I had to do is give Documents/Knight
as a public directory for firebase init.所以我要做的就是将
Documents/Knight
作为 firebase init 的公共目录。 After I did this I called firebase serve and firebase deploy and it worked perfectly.完成此操作后,我调用了 firebase 服务和 firebase 部署,它运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.