How do I make a custom subdomain on Firebase?

核能气质少年 提交于 2019-11-26 15:24:10
Chris Raynor

Update

You can now add multiple domains to a single Firebase Hosting site. Domains can either serve site content or redirect to another domain (editable at any time). In addition, you can now use subdomains of the same registered domain on different projects, such as example.com on one project and blog.example.com on another. Visit your hosting admin page to configure them.

Original answer

If you point multiple subdomains of mydomain.com to Firebase Hosting, it will redirect others to the one you chose when specifying your custom domain. If you're looking to simply serve content from one subdomain, all you need do is specify that one in the custom domain field on you Hosting tab and point your DNS for that subdomain to Firebase Hosting, following the instructions provided.

If, however, you're looking to serve different content on different subdomains, that's not currently possible, though this is a highly requested feature that we're considering implementing

i believe you can use rewritte rules on the hosting configuration json file

since all domains and subdomains you point to your firebase project will be redirected to your single firebase hosting bucket, youll need to set up custom rewrite rules for each domain you want to separate, to redirect them to an specific folder or cloud function in your project.

i suggest to check the next url as reading material, its a new techinque to work with projects in firebase https://github.com/jthegedus/firebase-functions-next-example

on your firebase.json file

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "/.well-known/assetlinks.json",
        "destination": "/instant/assetlinks.json"
      },
      {
        "source": "sub.domain.com/**",
        "destination": "/subdomain/**"
      }
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!