Firebase Hosting Multiple Sites
March 12, 2020Create multiple sites
Goto Firebase Console -> Hosting
, then Advance -> Add another site
.
Select a site name
, also known as resource name
.
Testing
Edit firebase.json
.
- Change
hosting
to array of objects. - Each hosting object should have a
target
field (known astarget name
). - Assign a different
public
directory for each hosting object
{
"hosting": [
{
"target": "main",
"public": "main/public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**",
"**/public-*/**"
],
"trailingSlash": false
},
{
"target": "app",
"public": "app/public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**",
"**/app/public-*/**"
],
"rewrites": [
{
"source": "/test",
"function": "test"
},
{
"source": "**",
"function": "nuxtssr"
}
],
"headers": [
{
"source": "**/_nuxt/*.*",
"headers": [{
"key": "Cache-Control",
"value": "public, max-age=31536000"
}]
}
],
"trailingSlash": false
}
],
}
Usage
firebase serve --only hosting:TARGET_NAME
or
firebase serve --only functions,hosting:TARGET_NAME
Deployment
Assign target name
to resource name
.
firebase target:apply hosting TARGET_NAME RESOURCE_NAME
The command above will update .firebaserc
{
"projects": {
"default": "PROJECT_ID"
},
"targets": {
"PROJECT_ID": {
"hosting": {
"TARGET_NAME": [
"RESOURCE_NAME"
],
"TARGET_NAME02": [
"RESOURCE_NAME02s"
]
}
}
}
}
Deploy
firebase deploy --only hosting:TARGET_NAME
NOTE: Cloud functions are shared between multiple sites (actually, functions
are independent from hosting
). Each hosting site can has its own rewrites
via firebase.json
.
- algo-trading
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- binance
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- contentresolver
- coroutines
- crashlytics
- crypto
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetpack-compose
- jetson-nano
- kotlin
- kotlin-serialization
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn