Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Hosting multiple subdomains to app directories with 1 project

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
      }
    ]
  },
like image 857
ColdLogic Avatar asked Dec 22 '18 01:12

ColdLogic


People also ask

Can you have multiple subdomains?

Each domain name can have up to 500 subdomains. You can also add multiple levels of subdomains, such as info.blog.yoursite.com. A subdomain can be up to 255 characters long, but if you have multiple levels in your subdomain, each level can only be 63 characters long.

Can you stack subdomains?

Yes. You can have as many levels as you like in DNS.

How many websites can I host on Firebase?

Consider using automatic SDK configuration to mirror multiple environments using a single codebase. The multisite feature supports a maximum of 36 sites per Firebase project.

What Alias do you want to use for this project eg staging?

Select the project you want to use for a different environment, and then give it an alias. The alias can really be whatever you want, but it's common to use aliases like “development”, “staging”, or “production”. Once you've created a new alias, it will be set as the current environment for deployment.


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)
like image 200
Neelavar Avatar answered Oct 26 '22 05:10

Neelavar