ScaffoldHub - v2
  • Introduction
  • Modeling
    • Two-way Relationships
  • Setup
    • Backend
    • Frontend
    • File Storage
    • Emails with SendGrid
    • Payments with Stripe
  • Debugging
  • Deployment
    • Database
      • SQL
      • MongoDB
    • Backend
      • Google Cloud - App Engine
      • Google Cloud - Run
      • Under construction...
    • Frontend
      • Firebase Hosting
      • Heroku w/ Subdomains
      • Under construction...
  • Features
    • Projects
    • Preview
    • Tenants
      • Single-Tenant
      • Multi-Tenant
      • Multi-Tenant (w/ subdomains)
    • Payments
    • Security
    • Authentication
      • Sign-in and Sign-up
      • Invitation
      • Password Reset
      • Password Change
      • Email Verification
    • Audit Logs
    • Settings
    • Internationalization (I18n)
    • Entity
      • Form
      • Filter and List
      • Export
      • Import
    • API Documentation
  • Architecture
    • Security
    • File Storage
    • Internationalization (I18n)
    • Payments
    • Typescript Support
    • Rate limiting
    • Technologies Versions
    • Under construction...
  • Recipes
    • Testing the API with Postman
    • Enterprise sign-in with WorkOS
    • Under construction...
  • Support
  • Changelog
    • Documentation
    • Scaffolds
  • Custom Development
  • Legacy Scaffolds
  • Go to ScaffoldHub
Powered by GitBook
On this page
  • Configure the frontend environment
  • Create a Firebase account
  • Install Firebase Tools
  • Sign in to Google
  • Init Firebase
  • Firebase Config Files
  • Deploy
  • Custom Domain

Was this helpful?

  1. Deployment
  2. Frontend

Firebase Hosting

PreviousFrontendNextHeroku w/ Subdomains

Last updated 4 years ago

Was this helpful?

is a Google solution for hosting static websites.

This solution for single and multi-tenant strategies only. It does not support subdomains.

This tutorial will use the production environment, but the steps for the staging environment are the same.

Configure the frontend environment

Go to the frontend environment configuration:

  • frontend/src/config/production.tsx (For React and Vue)

  • frontend/src/environments/environment.production.ts (For Angular)

Replace the backendUrl variable for the corresponding URL.

Don't forget the/api suffix.

// Place the URL here with the /api suffix.
// Ex.:`https://domain.com/api`;
const backendUrl = `https://your_production_backend_url/api`;

Create a Firebase account

Go to and create a Firebase account.

Install Firebase Tools

npm install firebase-tools -g

Sign in to Google

firebase login

Init Firebase

Go to the frontend folder, and run:

firebase init

Mark only the Hosting option.

Select Use an existing project.

Select the production project.

When asked:

What do you want to use as your public directory?

  • build (for React)

  • dist (for Vue)

  • dist/frontend (for Angular)

Configure as a single-page app (rewrite all urls to /index.html)?

Answer Y.

Firebase Config Files

The firebase.json file will look like this:

{
  "hosting": {
    "public": "build" OR "dist" OR "dist/frontend",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Change the .firebaserc to manage both staging and production environments.

{
  "projects": {
    "staging": "",
    "production": "name-of-the-production-project"
  }
}

On the frontend/package.json, add those two new scripts:

{
  ...
  "scripts": {
    ...
    "deploy:staging": "npm run build:staging && firebase use staging && firebase deploy",
    "deploy:production": "npm run build:production && firebase use production && firebase deploy",
  },
  ...
}  
  • npm run build:<environment> build the environment using the proper config file. That's needed to build the app with the correct backendUrl.

  • firebase use <environment> makes sure the files will be deployed to the correct environment.

  • firebase deploy deploys the files.

Deploy

npm run deploy:production

You will now receive the frontend URL.

Go to the configuration file and replace those values:

const frontendUrl = {
 host: '<firebase_production_project_id>.web.app',
 protocol: 'https',
};

Redeploy the application.

Custom Domain

To add a custom domain, follow those steps:

Firebase Hosting
backend server
https://console.firebase.google.com
https://firebase.google.com/docs/hosting/custom-domain