Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Hosting, create a 404 page

I'm using Firebase to host a domain with some static html, javascript and images. It works great. The last thing I want to do, is creating a custom 404-error page. According to the Firebase Hosting Documentation (link) I only have to put a file called '404.html' inside the project public directory. It doesn't work. A tree view of my project directory:

  • 404.html
  • index.html
  • images (directory)
  • robots.txt

My firebase.json file looks like this:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "domain.com",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

What am I doing wrong? Thanks.

like image 853
Jasper Avatar asked Aug 14 '17 10:08

Jasper


People also ask

Can you use firebase to host a website?

Firebase Hosting is production-grade web content hosting for developers. With a single command, you can quickly deploy web apps and serve both static and dynamic content to a global CDN (content delivery network).

Does firebase Hosting have DDoS protection?

Restrict access and counter a DDoS attack for your web apps For example, with just a few lines of code, you can integrate popular Node. js middleware offerings to build additional security layers, like access management by IP or protection from denial-of-service (DDoS) attacks.

How do I deploy HTML in firebase Hosting?

Deploy HTML Static Website to Firebase HostingClick the Add Project for creating a new Firebase project. Cut all the source code (note only our source code like CSS, IMG, JS, and index. html, and any others you have) to the newly created public folder after the cut operation the file manager looks like this.


1 Answers

Your source is:

"source": "**"

This causes all routes to go to the index.html file. Since all routes go there, it will never throw a 404. If you want the 404 to work, you must specify the routes that actually work. ie:

"source": "/"
like image 196
Notmfb Avatar answered Sep 24 '22 05:09

Notmfb