Firebase Hosting
Firebase Hosting 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 backend server URL.
Don't forget the/api
suffix.
Create a Firebase account
Go to https://console.firebase.google.com and create a Firebase account.
Install Firebase Tools
Sign in to Google
Init Firebase
Go to the frontend folder, and run:
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:
Change the .firebaserc to manage both staging and production environments.
On the frontend/package.json, add those two new scripts:
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
You will now receive the frontend URL.
Go to the configuration file and replace those values:
Redeploy the application.
Custom Domain
To add a custom domain, follow those steps:
Last updated