0

Background

I'm using Heroku's Review Apps feature. It deploys a new app instance for each github pull request opened, and assigns it a unique URL of the format

my-app-pr-1234.myapp.herokuapp.com

My app makes heavy use of subdomains, which Heroku doesn't support (see answer here).

They require that I purchase and set up a DNS record to handle the subdomain, so I purchased example.com

Question

Each pull request will generate it's own unique URL. And I don't want to set up a new DNS record for each, I'd rather set up one generic DNS record.

How do I set up DNS so that it "parses" the subdomain of the incoming request and directs it to the correct app?

Example:

  • I visit foo.pr-1738.example.com
  • I'd like DNS to parse out the requested subdomain and point to my-app-pr-1738.myapp.herokuapp.com (the subdomain foo will be handled by the app itself)

Is this possible?

Side note: I use DNSimple for DNS record management, although this question applies to DNS in general.

user2490003
  • 10,706
  • 17
  • 79
  • 155

1 Answers1

0

How do I set up DNS so that it "parses" the subdomain of the incoming request and directs it to the correct app?

You can't, not using simply the DNS protocol, and unless all the hostnames are handled by the same backend server (which you can't really assume as Heroku may route different subdomains set to separate IPs).

If each app has a custom hostname attached and they all follow an unique schema e.g. <pr-1738>.example.com, then you can create a wildcard

*.example.com

that points to the main Heroku hostname. Again, this is not guaranteed to always work as Heroku may handle the apps A.example.com and B.example.com from different IPs. But it may work in most cases.

Otherwise, the real correct approach would be to provision the appropriate DNS record upon the creation of the app.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364