简体   繁体   中英

Firebase hosting static website not working

I am trying to host a static website on firebase. ( using macOS Catalina ) I installed firebase CLI with npm. The directory of my website is called Knight After logging in, I run this command:

firebase init

Then I chose the following: Which Firebase CLI features do you want to set up for this folder?

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)?

Y ( I also tried No )

File public/index.html already exists. 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. 在此处输入图像描述

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. 在此处输入图像描述

The process that the Firebase CLI uses is pretty straightforward:

  1. You run firebase init in a specific directory
  2. Answer the "What do you want to use as your public directory?" question with the path to your index.html and other web files relative to the directory where you run 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?" with Knight .


Update : It seems that you are running the firebase init command in the same directory where your index.html file is. 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. So my path to index.html would look like:

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

But firebase is writing the files in:

/Users/DCI

So what I had to do is give Documents/Knight as a public directory for firebase init. After I did this I called firebase serve and firebase deploy and it worked perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM