This is really two questions.
So I guess I'll answer it like that.
How can I allow customers to add a custom domain to my heroku-based app?
So, in your example, their domain name is www.user1.com
Two things need to happen
www.user1.com
needs to be added to your heroku domains for the app
- the dns for
www.user1.com
needs to be set to the heroku servers
In order to add this new domain, I guess you need to store the custom domain in the app,
and when it is changed, or created, ensure a queued task is setup to push this config change to heroku.
In order to do the dns correctly, I hope it is enough that they add a CNAME
for user1.app.com
.
Therefore, if you have a wildcard CNAME linking to heroku's dns, you can avoid the type of downtime that can occur if Heroku gets DOS-ed again.
How can I show content based on domain, rather than just subdomain?
Well, somehow you already differentiate user1.app.com
from user2.app.com
Maybe you just sniffed request.host
.
Now you just have to try the custom domain first.
Maybe this'll work.
before_filter :set_client
def set_client
@client = Client.find_by_custom_domain(request.host) || Client.find_by_subdomain(request.host.split(".").first)
unless @client
raise "unrecognised domain #{request.host}"
end
end