Manage branch subdomains without Netlify DNS

In the last weeks, I have been moving the Front Matter CMS documentation and APIs to different hosting providers. The documentation and APIs were hosted on Vercel, but they stopped their open-source program, which made me look for alternatives. I decided to move the documentation to Netlify and the APIs to Azure.

The documentation site is generated with Next.js and uses the main and dev branches to deploy the production (frontmatter.codes) and beta (beta.frontmatter.codes) versions.

Branch domains

On Vercel, you can add a domain to a specific git branch.

Show image Configure your branch domain on Vercel
Configure your branch domain on Vercel

On Netlify, you can do the same with branch subdomains. This feature allows you to have a subdomain for each branch, and Netlify will deploy the branch to that subdomain.

You must enable the branch deploys feature on Netlify for this to work. You can configure this on the site configuration page, under the branches and deploy contexts section.

Show image Enable branch deploys on Netlify
Enable branch deploys on Netlify
important

One thing to note is that you cannot change the subdomain name. It automatically becomes the name of the branch.

As I was using dev as the branch name, the subdomain becomes dev.frontmatter.codes.

Show image Add your branch subdomain on Netlify
Add your branch subdomain on Netlify
note

A solution to be able to use beta.frontmatter.codes instead of dev.frontmatter.codes, was to rename the dev branch to beta. Another option I chose was to use my own DNS provider, Cloudflare, to manage the subdomains.

Manage branch subdomains

In the branch subdomains documentation from Netlify, you can find a link to manage the branch subdomains with your own DNS provider, which made me move back to Cloudflare.

When you want to add your subdomain for a specific branch, ensure it is deployed on Netlify.

Netlify deploys your production branch (defined in the branches and deploy contexts setting) to the https://<project-name>.netlify.app domain. You can find this information on the production domains overview.

Show image Production domains on Netlify
Production domains on Netlify

The branch deploys are available at https://<branch-name>--<project-name>.netlify.app.

For Front Matter CMS, the URLs are:

  • Production: https://frontmattercms.netlify.app
  • Beta: https://beta--frontmattercms.netlify.app (since writing this post, I have changed the branch name from dev to beta for consistency)

Once you know your branch URL, you can add a CNAME record to your DNS provider. In Cloudflare, you can add a CNAME record with the following settings:

  • Type: CNAME
  • Name: beta
  • Target: <branch-name>--<project-name>.netlify.app
Show image Subdomain configuration for your Netlify branch URLs
Subdomain configuration for your Netlify branch URLs
tip

When you use your own DNS provider, you can define your subdomain name instead of using the name of the branch. For the example, I added the dev name and linked it to the beta--frontmatter cms.netlify.app, which allows me to use the dev.frontmatter.codes subdomain for the beta branch.

Once you have added the CNAME record, wait a few minutes for the DNS to propagate, and you will be able to access your branch subdomain.

Comments

Back to top