Custom Subdomain for git branches
cf pages automatically creates
${branchName}.my-app.pages.dev
and that is great but I don't want to expose any *.pages.dev.
my app is deployed at app.mydomain.com
and I'd like the alpha or beta branch to be accessible at alpha.app.mydomain.com
& beta.app.mydomain.com
respectively.
I can add alpha.app.mydomain.com
along side app.mydomain.com
under the custom domains
section but it resolves as an alias of app.mydomain.com
and I fail to see how I can choose what deployment is associated to a specific domain.
In case it's any relevant, please note that I build my next app on a self-hosted ci using npx @cloudflare/next-on-pages
and deploy using wrangler with the --branch
option.
I can easily create 3 different apps for each domain but would of course prefer to keep things centralized2 Replies
Hey,
You can achieve this by changing the cname target to
alpha.my-app.pages.dev
and beta.my-app.pages.dev
respectively, as long as you are using CF DNS:
https://developers.cloudflare.com/pages/how-to/custom-branch-aliases/Cloudflare Docs
Add a custom domain to a branch · Cloudflare Pages docs
In this guide, you will learn how to add a custom domain (staging.example.com) that will point to a specific branch (staging) on your Pages project.
Hey! Thanks for the prompt response.
I'm 100% cloudflare, DNS + Pages, moving out of vercel for my greatest delight.
I thought I had tried this and stumbled upon an SSL error but it looks like it works fine now. Love your service guys.
Cheers