Firebase Hosting multiple subdomains to app directories with 1 project

Viewed 3301

I currently have an app deployed to Firebase hosting with the following structure:

public/
    appSub1/
        index.html
    appSub2
        index.html
    index.html

I have already added and connected my subdomains such that

appSub1.mysite.com/ -> app.firebaseapp.com/
appSub2.mysite.com/ -> app.firebaseapp.com/

I am trying to configure the redirects to properly associate the subdomains with the correct app subfolder such that

appSub1.mysite.com/ -> app.firebaseapp.com/appSub1/
appSub2.mysite.com/ -> app.firebaseapp.com/appSub2/

The app is still correctly displayed if I manually add the sub paths, but not without them. So going to appSub1.mysite.com/ just ends up at a blank page, but going to appSub1.mysite.com/appSub1/ ends up at the correct index.html

This is my current hosting configuration in firebase.json

"hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "appSub1.mysite.com/**",
        "destination": "/appSub1/**",
        "type": 301
      },
      {
        "source": "appSub2.mysite.com/**",
        "destination": "/appSub2/**",
        "type": 301
      }
    ]
  },
1 Answers

I recommend the following:

  1. Upgrade to Blaze plan on Firebase
  2. Use Firebase Multi-site Hosting method (refer: https://firebase.google.com/docs/hosting/multisites)
  3. Break public/app1 and public/app2 into two separate hosting project targets - say app1 and app2 - thus, by default the hosting address would be app1.firebaseapp.com and app2.firebaseapp.com (or now as of May 2019, you'll get a .web.app domain as well - app1.web.app
  4. Connect individual subdomains by configuring DNS entries on your domain registry (refer: https://medium.com/@fransandi/use-firebase-multisite-hosting-to-associate-multiple-domains-subdomains-to-your-project-ee099109bfe9)
Related