Search code examples
firebasegoogle-cloud-functionsfirebase-hosting

Multiple domains serving independent content with Firebase hosting and Cloud Functions?


I'm designing and building a web app in which users will upload a static HTML template file. My system will parse their template and create JavaScript code for their individual purpose.

I want each use to have their own namespace, so ideally the endpoints would look something like this

user1.domain.com/index.html
user1.domain.com/code.js

user2.domain.com
user2.domain.com/code.js

...

It's not possible to programmatically write static files to Firebase hosting, so I envisaged having a Cloud Function that would inspect the HTTP host and serve up the appropriate files. User 1's index.html template file would be stored in Firebase Storage in its own sub-space and User 2's in a similar manner.

The end goal is to have www.userone.com and www.usertwo.com (my customers chosen domains) mapped to user1.domain.com and user2.domain.com respectively, but I could achieve this using an external CDN proxying requests.

In order for the above solution to work I would need to manually add domains to my Firebase project (using the Firebase control panel) as each user participates in my app. I expecting around 200 customers total.

I could use staging.domain.com/user-{n} and then I would only have to configure a single domain for my Firebase project. However, this would force users to have to use relative links to their content within their template. Also, they would have access to other users content i.e. user-1/index.html could access ../user-2/code.js which isn't a security risk but invites more error prone idiocies from users.

Is there a way to configure the hosting to map *.domain.com to a single Cloud Function, or at least user1.domain.com, user2... manually?

If not, can the above scenario be achieved using Google Cloud Infrastructure? (My concern is there is an undocumented limit to the number of domains that can be attached to a single project.)


Solution

  • Is there a way to configure the hosting to map *.domain.com to a single Cloud Function, or at least user1.domain.com, user2... manually?

    You can map multiple domains to a Firebase Hosting project. But each domain will serve the exact same content.

    There is no way to configure Firebase Hosting to serve different content for different domains mapped to the same project.

    Also see: