Bird
Raised Fist0
Firebasecloud~5 mins

Why Firebase Hosting serves web apps - Why It Works

Choose your learning style10 modes available
Introduction
Firebase Hosting helps you put your web app online quickly and safely. It solves the problem of making your website available to anyone on the internet with fast loading and secure connections.
When you want to share your personal website or portfolio with friends and employers.
When you build a small business website and want it to load fast for visitors.
When you create a web app and need a simple way to publish it without managing servers.
When you want automatic security with HTTPS so visitors feel safe.
When you want to update your website easily and see changes live quickly.
Config File - firebase.json
firebase.json
{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

This file tells Firebase Hosting where your website files are located (the public folder). It also tells Firebase to ignore certain files and folders when uploading. The rewrites section makes sure that all URLs load your main index.html file, which is important for single-page web apps.

Commands
This command logs you into your Firebase account so you can manage your projects and hosting.
Terminal
firebase login
Expected OutputExpected
✔ Success! Logged in as your-email@example.com
This command sets up Firebase Hosting in your project folder. It creates the configuration files and the public folder for your website files.
Terminal
firebase init hosting
Expected OutputExpected
=== Hosting Setup ? What do you want to use as your public directory? public ? Configure as a single-page app (rewrite all urls to /index.html)? Yes ? Set up automatic builds and deploys with GitHub? No Firebase Hosting setup complete.
This command uploads your website files to Firebase Hosting and makes your web app live on the internet.
Terminal
firebase deploy --only hosting
Expected OutputExpected
=== Deploying to 'your-project-id' i deploying hosting i hosting[your-project-id]: beginning deploy... ✔ hosting[your-project-id]: deployed successfully ✔ Deploy complete! Project Console: https://console.firebase.google.com/project/your-project-id/overview Hosting URL: https://your-project-id.web.app
→
--only hosting - Deploy only the hosting part without affecting other Firebase services
This command opens your live website in the default web browser so you can see your deployed web app.
Terminal
firebase open hosting:site
Expected OutputExpected
No output (command runs silently)
Key Concept

Firebase Hosting serves web apps by securely delivering your website files fast and making them available to anyone on the internet with simple commands.

Common Mistakes
Not running 'firebase login' before deploying
Without logging in, Firebase cannot verify your identity and will block deployment.
Always run 'firebase login' first to authenticate your account.
Not setting the correct public directory during 'firebase init hosting'
If the public folder is wrong, Firebase will upload the wrong files or no files at all, so your site won't work.
Specify the folder where your website files are stored, usually 'public'.
Forgetting to run 'firebase deploy' after making changes
Your updates won't appear online until you deploy them.
Run 'firebase deploy --only hosting' each time you want to update your live site.
Summary
Use 'firebase login' to sign in to your Firebase account.
Run 'firebase init hosting' to set up hosting configuration and folders.
Deploy your web app with 'firebase deploy --only hosting' to make it live.
Open your live site with 'firebase open hosting:site' to verify deployment.

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

  1. Step 1: Understand HTTPS purpose

    HTTPS encrypts data between the user and the server to keep it safe from attackers.
  2. Step 2: Apply to Firebase Hosting

    Firebase Hosting uses HTTPS by default to protect users visiting your web app.
  3. Final Answer:

    To keep the connection secure and protect user data -> Option D
  4. 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

  1. Step 1: Identify the entry point for web apps

    Single-page apps start by loading the main HTML file, which is usually index.html.
  2. Step 2: Confirm Firebase Hosting behavior

    Firebase Hosting serves index.html first to load the app shell and then loads scripts and styles.
  3. Final Answer:

    index.html -> Option A
  4. 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:
{
  "hosting": {
    "rewrites": [
      { "source": "**", "destination": "/index.html" }
    ]
  }
}
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

  1. Step 1: Understand the rewrite rule

    The rule sends all requests (**) to /index.html, regardless of the URL path.
  2. Step 2: Apply to /profile URL

    When user visits /profile, Firebase Hosting serves index.html, letting the app's JavaScript handle the route.
  3. Final Answer:

    The server serves the index.html file so the app can handle the route -> Option B
  4. 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

  1. 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.
  2. 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.
  3. Final Answer:

    Add a rewrite rule in firebase.json to send all routes to /index.html -> Option A
  4. 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

  1. 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.
  2. Step 2: Configure Firebase Hosting rewrites

    Adding a rewrite rule sending all requests to /index.html ensures the app loads correctly on any URL.
  3. Final Answer:

    Set a rewrite rule in firebase.json to send all requests to /index.html -> Option C
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard