How to add custom hostname for multi tenant application with cloudflare pages ?
In order to have multi tenant support for cloudflare pages I followed this steps.
Step 1:
Deploy the application to cloudflare pages and set custom domain
app.mycompany.com
Step 2:
Wrote a simple cloudflare worker proxy
Step 3:
Added the worker route as on different domain mycompany.site
*.mycompany.site/*
I chose a seperate domain for multi tenant apps, so that its easier to maintain the CNAME if later on I wanted to add subdomains to my primary domain mycompany.com
Another reason was that having a seperate domain makes it easier to have a proxy worker route for only purpose of multitenant.
( Please do suggest if there is a better approach, if I could use the existing domain for this)
Now From this step onwards, things are getting a little of confusing to me
Step 4:
I added a wildcard record to mycompany.site
DNS
AAAA * 100:: Proxied
Step 5:
Enabled Custom Hostnames for mycompany.site
Step 6:
Added custom hostname example.com
Step 7:
I didnt understand this part13 Replies
So Cloudflare needs to be able to issue certificates for your custom domain.
Basically, you add a custom hostname, then add that DNS record (the _acme-challenge one) for your hostname to allow it to issue a certificate, and then finally add the CNAME for your custom hostname
yes tried to follow this steps, but was getting error of 522 / 1016
The flow diagram was something like this
After a bit of of time, The proxied worker didnt work as well
how do you go from a proxied fallback record to your app record pointing at the pages.dev?
needs to be something in the middle lol, there's nothing connecting the fallback 192.2.0.1 to the app cname
oh I see the bottom part now, you have
*.saas.com/*
You need */*
or specific routes for each of the customer domains, Worker Routes see the customers hostname (example.com) and therefor wouldn't match on saas.comCloudflare Docs
Workers as your fallback origin · Cloudflare for Platforms docs
Learn how to use a Worker as the fallback origin for your SaaS zone.
haha i knew that I definitely did something silly. can you suggest a better way to achieve this ?
In a gist, my multi tenant application is at app.saas.com, i want users to access saas at username.saas.com while also being able to set custom domain if they want to.
Well Pages can't use wildcards or anything like that, so a Worker is going to have to sit in front of both ways
as for worker as origin i think having a seperate domain for custom hosting would be perfect choice like customer.saas.cloud or something
You could have different workers (one for
*.saas.com/*
, and one for */*
handling all the custom domains, the more specific one wins), or use the same one for both and a singular wildcard, and then just route smartly based off the hostnamewhere / worker route would be on saas.cloud zone
might make some of it cleaner if you had a separate domain for custom hostnames yea
now i got it. thanks