'Can I add a domain to Firebase hosting via the API?
I want to be able to add domains to Firebase hosting with the API instead of the web UI, is that possible?
I want to add potentially hundreds of domains, is there a domain limit per project in Firebase?
Solution 1:[1]
As far as I can tell from the entire CLI documentation, there isn't any way to do this.
Lets take a step back and consider what the web UI process involves i.e. the generation of a TXT record to add to your DNS records, after verifying the presence of said TXT record on the domain, providing A records that you (authorized owner) add to allow redirecting to your firebase hosted site.
In my opinion, this very manual back and forth is necessary as a security measure. The only way it is taken out of the equation via the CLI is by providing a means for you to authenticate ownership of a domain (registered with any one of many domain registrars), and being granted authorization to change your A records. These are both outside the scope of Firebase, and could potentially introduce severe security flaws. Regardless, even if it existed, it would still have to be step-by-step and somewhat manual via CLI rather than the single command it sounds like you're looking for.
Solution 2:[2]
It is not possible to add custom domains automatically through an API at this time.
Nor would it allow you to create a reseller or multi-tenant project (i.e. connect a large number of domains or subdomains dynamically) since you cannot connect more than about 36 domains connected to one project.
Solution 3:[3]
It's possible to add domains using Firebase Hosting Rest Api. I am not sure why they didn't put it on their official website but I checked today and it works. https://developers.google.com/resources/api-libraries/documentation/firebasehosting/v1beta1/java/latest/com/google/api/services/firebasehosting/v1beta1/FirebaseHosting.Sites.Domains.html
Solution 4:[4]
Answer that I've received from Firebase support:
There is no API yet that would allow you to add custom domains, it was requested as a feature before but unfortunately we have no more information on that - so for now, only the Console UI allows you to do it.
When it comes to the limits, in a project, a custom domain is attached to a site - there can be 36 sites per project, and for one site there is no hard limit, but we recommend not exceeding 20 custom domains. You can experience technical issues with SSL certs when you exceed 20 domains per site, which we won’t be able to troubleshoot since the system was not designed for such use cases.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | WittyID |
Solution 2 | Kato |
Solution 3 | Michal Kubizna |
Solution 4 | aponski |