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:
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.
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).
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.
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.
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": "/"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With