📖 Scenario: You want to share your simple web app with friends and users worldwide. You decide to use Firebase Hosting, a service that puts your web files on the internet so anyone can open your app in their browser.
🎯 Goal: Build a basic Firebase Hosting setup that serves a simple web app with an index.html file.
📋 What You'll Learn
Create a folder named public with an index.html file inside
Add a Firebase configuration file firebase.json to specify hosting settings
Initialize Firebase Hosting to serve files from the public folder
Deploy the web app so it is accessible via a Firebase Hosting URL
💡 Why This Matters
🌍 Real World
Firebase Hosting is used by developers to quickly and securely publish web apps and static websites to the internet without managing servers.
💼 Career
Understanding Firebase Hosting is useful for frontend developers, web designers, and cloud engineers who want to deploy web apps easily and reliably.
Progress0 / 4 steps
1
Create the public/index.html file
Create a folder named public and inside it create a file called index.html with this exact content: <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>My Firebase App</title></head><body><h1>Welcome to Firebase Hosting!</h1></body></html>
Firebase
Hint
Make sure the file is named exactly index.html inside the public folder.
2
Add the firebase.json configuration file
Create a file called firebase.json in your project root with this exact content to tell Firebase Hosting to serve files from the public folder: { "hosting": { "public": "public", "ignore": ["firebase.json", "**/.*", "**/node_modules/**"] } }
Firebase
Hint
This file tells Firebase which folder to use for hosting your web app files.
3
Initialize Firebase Hosting
Run the command firebase init hosting in your terminal to set up Firebase Hosting. When prompted, select the public folder. This step prepares your project for deployment.
Firebase
Hint
This command sets up Firebase Hosting in your project and links your files.
4
Deploy your web app to Firebase Hosting
Run the command firebase deploy --only hosting in your terminal to upload your web app files to Firebase Hosting. This makes your app available on the internet at the Firebase Hosting URL.
Firebase
Hint
This command uploads your files and makes your app live on Firebase Hosting.
Practice
(1/5)
1. Why does Firebase Hosting serve web apps over HTTPS by default?
easy
A. To make the website load slower
B. To disable images from loading
C. To block users from accessing the app
D. To keep the connection secure and protect user data
Solution
Step 1: Understand HTTPS purpose
HTTPS encrypts data between the user and the server to keep it safe from attackers.
Step 2: Apply to Firebase Hosting
Firebase Hosting uses HTTPS by default to protect users visiting your web app.
Final Answer:
To keep the connection secure and protect user data -> Option D
Quick Check:
HTTPS = Secure connection [OK]
Hint: HTTPS means secure connection, always used by Firebase Hosting [OK]
Common Mistakes:
Thinking HTTPS slows down the site
Believing HTTPS blocks users
Confusing HTTPS with disabling images
2. Which file does Firebase Hosting usually serve first when loading a single-page web app?
easy
A. index.html
B. style.css
C. main.js
D. firebase.json
Solution
Step 1: Identify the entry point for web apps
Single-page apps start by loading the main HTML file, which is usually index.html.
Step 2: Confirm Firebase Hosting behavior
Firebase Hosting serves index.html first to load the app shell and then loads scripts and styles.
Final Answer:
index.html -> Option A
Quick Check:
First file loaded = index.html [OK]
Hint: Web apps start with index.html file [OK]
Common Mistakes:
Choosing JavaScript or CSS files as first load
Confusing config files like firebase.json as entry
Not knowing the role of index.html
3. Given this Firebase Hosting rewrite rule in firebase.json:
What happens when a user visits /profile in a single-page app?
medium
A. The server returns a 404 error because /profile does not exist
B. The server serves the index.html file so the app can handle the route
C. The server redirects the user to the homepage URL
D. The server serves a blank page
Solution
Step 1: Understand the rewrite rule
The rule sends all requests (**) to /index.html, regardless of the URL path.
Step 2: Apply to /profile URL
When user visits /profile, Firebase Hosting serves index.html, letting the app's JavaScript handle the route.
Final Answer:
The server serves the index.html file so the app can handle the route -> Option B
Quick Check:
Rewrite all URLs to index.html = The server serves the index.html file so the app can handle the route [OK]
Hint: Rewrite '**' to index.html serves all app routes [OK]
Common Mistakes:
Expecting 404 error for app routes
Thinking server redirects to homepage
Assuming blank page is served
4. A developer sets up Firebase Hosting but their single-page app shows a 404 error on routes like /dashboard. What is the likely fix?
medium
A. Add a rewrite rule in firebase.json to send all routes to /index.html
B. Remove the index.html file from the hosting folder
C. Disable HTTPS in Firebase Hosting settings
D. Change the app to use multiple HTML files for each route
Solution
Step 1: Identify cause of 404 on app routes
Without rewrite rules, Firebase Hosting looks for actual files matching the URL and returns 404 if missing.
Step 2: Apply rewrite rule fix
Adding a rewrite rule to send all routes to /index.html lets the app handle routing and prevents 404 errors.
Final Answer:
Add a rewrite rule in firebase.json to send all routes to /index.html -> Option A
Quick Check:
Rewrite rule fixes 404 on SPA routes [OK]
Hint: Rewrite all routes to index.html to fix SPA 404 errors [OK]
Common Mistakes:
Deleting index.html file
Disabling HTTPS thinking it helps
Using multiple HTML files instead of SPA routing
5. You want your Firebase Hosting to serve a React single-page app that uses client-side routing. Which configuration ensures all URLs load your app correctly?
hard
A. Disable rewrites and rely on default file serving
B. Upload separate HTML files for each route like /about.html and /contact.html
C. Set a rewrite rule in firebase.json to send all requests to /index.html
D. Use HTTP instead of HTTPS to avoid routing issues
Solution
Step 1: Understand React SPA routing needs
React SPA uses client-side routing, so all URLs must load the same index.html to let JavaScript handle routes.
Step 2: Configure Firebase Hosting rewrites
Adding a rewrite rule sending all requests to /index.html ensures the app loads correctly on any URL.
Final Answer:
Set a rewrite rule in firebase.json to send all requests to /index.html -> Option C
Quick Check:
Rewrite all URLs to index.html for SPA routing [OK]
Hint: Rewrite all URLs to index.html for React SPA [OK]
Common Mistakes:
Uploading multiple HTML files for SPA routes
Disabling rewrites causing 404 errors
Switching to HTTP thinking it fixes routing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.