rails 🚀
HerokuApps and Multiple Domains
<p>There are some great docs online for figuring out how to setup heroku domains.</p> <p><a href="https://devcenter.heroku.com/articles/custom-domains">https://devcenter.heroku.com/articles/custom-domains</a> as well as others.</p> <p>The feature I had to get setup was that for <strong>every new herokuapp</strong> I spun up under my account/clients account it had to make a sub-domain under that SaaS owners zone/domain.</p> <p>For example the owner wanted all of these apps to show up under freesurvey.com (not really but just an example url)&nbsp;so each one they spun up would be, for example yoursite.freesurvey.com but also later the person who &quot;subscribed&quot; for the product&nbsp;can also use their real domain like www.mysite.com or survey.mysite.com so it would be fully branded under their name as well.</p> <p>The interface for the owner and the subscriber would allow them to do 2 things. One they could enter the sub-domain they wanted eg &quot;yoursite&quot; as long as it was free to use in the owners domain name spacing eg &quot;freesurvey.com&quot;. Just as you see with basecamp or freshbooks. Second they had a field to enter a full domain they wanted to point here as well eg &quot;survey.mysite.com&quot; to quickly setup the subscriber if they were ready to do that. &nbsp;Keeping in mind each site is a new herokuapp which is really a new IP address. And heroku does not suggest the use of this IP address but to use the herokuapp name as I use below.</p> <p>After clicking save a few things took place.</p> <ol> <li>A new herokuapp was spun up from the master git branch&nbsp;</li> <li>The herokuapp was given a name that is available from heroku, in my case I ran &quot;heroku create --app NAMEHERE<sup>1</sup>&quot; using a name the script would produce that I am about 99% sure was available at heroku. But at this point it could just use the one heroku gives it and pass it back to the script.</li> <li>During the heroku install the&nbsp;zerigo_dns addon was added.&nbsp;</li> <li>The script then adds a domain to heroku via the command &quot;heroku domains:add&nbsp;NAMEHERE.freesurvey.com&quot;&nbsp;this automatically submits that domain via the add on &quot;<a href="http://zerigo_dns" target="_blank">zerigo_dns</a>&quot; so now my DNS records for that domain &quot;freesurvey.com&quot; includes a CNAME to NAMEHERE.freesurvey.com that points to proxy.heroku.com. The benefit here is that I can do this all in the script at the command line and API to setup the herokuapp so it will respond to the this domain, and the DNS so that it knows of this new subdomain and what to do with it.<br /> <br /> A Wildcard DNS record for freesurvey.com would not have worked since each record points to the herokoapp which is it&#39;s own domain/IP. So NAMEHERE<strong>1</strong>.herokuapp.com and&nbsp;NAMEHERE<strong>2</strong>.herokuapp.com&nbsp;are typically&nbsp;a different server and IP. I did not want all of these sites on one server and I wanted to use a Paas provider like heroku for reasons I note <a href="http://www.alfrednutile.info/posts/23" target="_blank">here</a>&nbsp;.&nbsp;</li> <li>Finally when the client who now uses this site is ready to point it to their own domain/zone they enter into the form &quot;survey.mydomain.com&quot; and this registers with the herokuapp via the command &quot;heroku domains:add&nbsp;survey.mydomain.com&quot;&nbsp;to accept requests from this domain and point it to &quot;NAMEHERE.herokuapp.com&quot;.<br /> <br /> So now it works for NAMEHERE.freesurvey.com, survey.mydomain.com and of course the name heroku was give to make the app&nbsp;it&nbsp;NAMEHERE.herokuapp.com. Of course the subscriber has to update their records that ONE time to point their CNAME survey.mydomain.com to ideally&nbsp;NAMEHERE.herokuapp.com</li> </ol> <p>&nbsp;</p> <p>Zerigo DNS&nbsp;<a href="https://devcenter.heroku.com/articles/zerigo_dns" target="_blank">https://devcenter.heroku.com/articles/zerigo_dns</a></p> <p>This was already setup for the client who owns the survey making SaaS site in this case for example &quot;freesurvey.com&quot; (not really this domain just an example)</p> <p>So Zerigo was the Name Server&nbsp;provider for this domain. And was linked to heroku account I made for the client.&nbsp;</p> <p>&nbsp;</p> <p><sup>1</sup>This name is made by Time.now.to_i via the ruby script prefixed with a consistent string of characters like freesurvey so I would end up with an App Name like freesurvey1234556789 which I could error check and make another until heroku says that was available. But that name is pretty rare so so far they are always available.</p>