Cloud functions reverse proxy for multiple domains

642 views
Skip to first unread message

Laurent Pellegrino

unread,
Jun 26, 2017, 10:27:59 AM6/26/17
to Firebase Google Group
Hello,

I am using Firebase for a service used by multiple customers. 

My service allows customers to create a project and then to list public information for this project at an URL that includes the project ID as HTTP parameter.

Firebase hosting is configured to use a custom domain: mydomain.com.

The response is created by a Firebase HTTP function based on the project ID.
 
Hosting requests to /project redirect to a Cloud Function using a rewrite.

At the end, a customer uses https://mydomain.com/project?id=xyz to access the public page.


My next step is to offer the possibility for customers to use their own domain for the public page. For instance, if a customer uses https://customer.com/project, then the resulting page is the same as https://mydomain.com/project?id=xyz.

The project ID is deduced from the customer domain or subdomain used.

I wonder if the current Firebase features and Cloud functions allow such kind of reverse proxy use case. I really like the possibility to control CDN caching from Cloud functions.

Before asking on this group I made a few tests. Currently, I am facing 2 issues for achieving what I would like to do:

1) How to retrieve the original request domain from a Cloud function?

I tried the following:

exports.test = functions.https.onRequest((req, res) => {
   
const host = req.get('host');
   
const origin = req.get('origin');


    console
.log('host=' + host);
    console
.log('origin=' + origin);


    res
.send(200, {
       
'host': host,
       
'origin': origin,
   
});
});



Unfortunately, when I call https://mydomain.com/test, I get undefined for origin and us-central1-XXX.cloudfunctions.net for host where XXX is my project name.

2) Firebase hosting allows connecting multiple domains. However, is there a limit on the number of domains? More importantly, is there an API to automate the creation of such connections?

Any ideas and suggestions are welcome.

Kind Regards,

Laurent Pellegrino
Reply all
Reply to author
Forward
0 new messages