Heroku is a robust leader in 12-factor deployment strategies. It is a large and feature-rich platform. You can deploy your app knowing that you are sitting on top of one of the best infrastructures on the planet for deployment and hosting. Importantly, when you are on Heroku, you don’t have to deal with infrastructure entropy or software entropy. Software entropy is the tendency of web servers to become outdated, security risks, or just plain crash over time.
You can’t realistically launch your own server, virtual or not, and expect it to keep working forever without your intervention.
When you pull back the curtain and consider how complicated deployment is, you understand that what Heroku is really doing for you is a highly necessary job of maintaining the hosting infrastructure and deployment infrastructure over time, thus reducing your cost.
Heroku is well-documented, but there’s a nuance regarding using the root of your domain name (also known as “the apex”) this article explains.
What it Means to use Your Root Domain Instead of www
The subtle distinction between running your website at a www subdomain and your root domain (also known as “apex” of your domain) is so subtle it is practically meaningless. The reason for this is that Chrome browser won’t display the www subdomain to the user the address by by default. Instead, it will show only the domain part without the www:
The distinction is so subtle to the user as to be meaningless. If you click into the address bar, you will — in an old-fashioned kind of way— see the full URL (including the http or https part, known as the “protocol”).
Behind the scenes, your website is actually operating at either:
2. another subdomain, or
3. no subdomain, which is called the apex of your domain (“apex” means the “top or highest part of”) or “root of” your domain.
Back in the 2000s, browsers didn’t do what I showed above. so it was common to see websites advertised as “www“.
The idea of “www” became so common place that like all good trends there was a backlash. In the 2010s, out of a desire to communicate a sleek new “Web 2.0” feel. Many new websites didn’t operating their websites at the www. subdomain at all— instead, just at the Apex of the domain.
As of 2021 this (irrelevant) decision is a mixed bag: Some websites still use www, many don’t.
Here, Zoom is operating their primary domain zoom.us with no subdomain:
Twitter, as well, operates with no subdomain:
Typically larger operations (like Amazon, Apple, Facebook) use subdomains because they may have dozens of different services at different subdomains and using the www subdomain is conceptually consistent with their organizational models.
Alternatively, I’ve noticed many newer, fashionable startups tend to use no subdomain and run their sites at the apex.
If you do this, or want to, you have some extra work. Although it’s possible to make an app respond to both www. and the root domain, I do not recommend it. The reason I don’t recommend it is that you will confuse your SEO if you create inbound links to separate subdomains. As well, you also confuse the browser settings (for example, the password autofill) if a users switches from the www to the root accidentally.
To avoid all fo this friction, pick one domain your users will access your website at. You will then need to redirect traffic from the other domain (www or the root) to the one you want as your primary website.
Using Your Root Domain on Heroku
ADVANCED: If you are not qualified to make changes to your domain records, please consider hiring a qualified web consultant to help you through these steps. My company, VERSO COMMERCE, can help you with DNS and Heroku.
From the Heroku docs:
On Heroku, if you want to use your root domain you must use a DNS Provider that supports either “ALIAS” records or something called “C-NAME Flattening” (basically the same thing)
This explanation is for you if:
• You are hosted on Heroku
• You want to use the “root” domain as discussed above. For instance, if your domain name is jasonfleetwoodboldt.com, then you would be using your website just like this one– at jasonfleetwoodboldt.com, not at www.jasonfleetwoodboldt.com
If this is you, you must use a special DNS provider, one that supports ALIAS records, like DNSimple. (Note: DNSimple is not the only provider that can support this, but it is one of the most popular ones. Many DNS providers flat out do not support this setup whatsoever.)
There are three types of DNS records you need to understand to understand why this limitation exists.
|A record||These records point domains or subdomains to specific IP addresses. They cannot point a subdomain to another named (that is, “conical name”) address, they can only point to specific IPv4 addresses (like 18.104.22.168). The limitation of A-records is that they can only point to (numerical) IP addresses.|
|CNAME record||These records point a subdomain to another subdomain, which may be part of your domain or not. The limitation of CNAME records is that you cannot apply a CNAME to the root of your domain.|
On Heroku, you are required to use CNAME records to point your domain to Heroku. You do this on the Settings > Domains tab.
First you will add the domain name you want to use. Click Add Domain
Heroku will tell you what your CNAME records are, they call it “DNS target”
You can copy it out of here or you can close this panel and copy it from the dashboard:
As you can see, Heroku has assigned some random words and characters to my domain:
This is a random “meaningless” DNS target assigned for your domain.
Heroku’s platform has a lot going on for it, but one of the most important thing is this.
Your dynos will rotate IP addresses. That means that unlike many other platforms, you can’t use fixed IP addresses.
For this reason, when you are hosting on Heroku, you can’t use A-records because they point to IP addresses and not to aliases.
The catch is this: Most DNS providers allow you to use only A-records for the root (apex) domain. (That is, you can’t use CNAME records.)
This means that if 1) you are on Heroku and 2) you want to use the root of your domain, you can’t use either of the DNS record strategies above.
The Alias Record
There is a magic type of DNS record that solves this problem: The Alias record.
DNSimple is also very commonly found among Heroku apps because it provides this special service: An A-record that behaves as if it is an A-record (with a fixed IP address), but in actuality points to a CNAME. The extra service part is that even if the IP addresses associated with that CNAME (DNS target) change, DNSimple automatically rotates the IP addresses for you behind the scenes.
It’s called an “alias record.”
DNSimple says this about their ALIAS record:
When someone makes a request for your root domain with DNSimple, the platform will try to resolve the alias record by looking up the remote domain (in your case, the Heroku domain), and behaving as-if your domain has A-name records with fixed IP addresses.
When Heroku rotates your IP addresses, it automatically picks up that rotation and changes its cached IP addresses.
In DNSimple, start by making sure that you don’t have either any A-records or CNAME records for the domain you are configuring on Heroku. (If you do, delete them.)
If you are configuring the root domain choose Add record > ALIAS. (If you are configuring a subdomain, use CNAME instead.)
Remember, in this example, we are configuring the Heroku app to work with the root of jasonfleetwoodboldt.com.
That’s it! Now you will may need to wait for DNS propagation, which will be determined by the “Time to live.” However, note that it will not be effective within 1 hour TTL, as shown here, but it will be effective from the last TTL that was set on the record. The shortest TTL possible is 10 minutes, the longest is 48 hours. So you will have to wait up to 48 hours if the TLL is very long. (DNSimple recommends and defaults to 1 hour which is appropriate for most websites.)
I hope you’ve enjoyed this article about how to configure DNSimple with Heroku at the root domain.