Can I mix top-level domain with subdomain applications on Heroku using "Custom Domains" add-on? - ruby-on-rails-3

According to heroku, http://addons.heroku.com/custom_domains
"The wildcard domain add-on enables you to use *.yourdomain.com. You can have as many wildcard domains as you like on one app."
Let say i have a domain call abc.com
can i use abc.com for 1st rails app, another.abc.com for 2nd rails app, another2.abc.com for 3nd rails app? this 3 rails is separate/different heroku rails app? i would like to know cause heroku say "as many wildcard domains as you like on one app."

Yes, this should be possible. You can condense your apps basically into 1 (if even necessary), and follow the guide here
http://www.railsdev.ws/blog/10/using-subdomains-in-rails-apps/
to learn how to route based on subdomains.

If you have 3 separate applications on Heroku as you describe then you just need a single custom domain per application (ie not the wildcard addon). If you use the wildcard domain addon to add say *.mydomain.com then you will not be able to use the same domain (mydomain.com) for any subsequent applications you host on Heroku.

Related

mysite.com/api and mysite/images not being aliased to my domain

I have a site being hosted on heroku so I can go to myapp.herokuapp.com/ and my SPA loads. I got a domain and used cloudflare with a CName record to alais mydomain.com to myapp.herokuapp.com. Great the sites load. Within my SPA i load some images. If my app loads directly from heroku *myapp.herokuapp.com/images/filex.png" it works fine but if I call (or type in the address bar) myDomain.com/images/files.png" I just get my site back like i types mydomain.com
Is this an issue with cloudflare? Do i need additional routing rules?
or is this an issue with my express server that is serving the app and images? does the redirected
request look different and do I need to add code to handle the redirect?
I'm not sure why the redirect is happening without more information. My best guess is that you need to follow these instructions from Heroku. Without this, Heroku servers will have no idea what to do with a request that has a host header of mydomain.com, and will perform in some unexpected way. Heroku needs some way on its side to know that all mydomain.com requests should be handled identically to myapp.herokuapp.com requests.
If this configuration is already in place, your underlying code needs to handle myapp.herokuapp.com and mydomain.com, but I believe by default express will not care about hostname.
Seems to have been an issue with heroku. It’s working fine on aws.

How to setup Heroku custom domain with DNS?

Short story: I build a web app, hosted it on Heroku, I have a domain from a Dutch provider "mijndomein.nl" Now I want to use the custom domain for my app.
I have followed the Heroku guide, but without success, I have watched a few videos, but the DNS settings in the videos are not exactly the same as I have at the mijndomein DNS control panel, and since I don't have a lot of experience setting up DNS and domain pointing I can't figure it out for my self. I will provide a screenshot of the mijndomein settings, and probably you will laugh that I haven't figured it out already and tell me how it works.
I'm confused with the * wildcard domain, and if the www (is a subdomain or not) that's not 100% clear in the Heroku guide. Heroku says that wildcard domains are not allowed when using ACM (automatic SSL certificate), but I need to obtain SSL ofc. and mijndomein's base settings looks to be using a * wildcard DNS. How do I set it up correctly so that when I enter:
oppascentrale.nl -> I go to my heroku app with SSL
www.oppascentrale.nl -> I go to my heroku app with SSL
Do I add with or without 'www' in the heroku control panel when adding custom domain?
This is how mijndomein DNS settings looks like when I do a factory reset
I'm also not sure if I can delete some of the DNS settings lines? I can't read anywhere if any of these different settings will interfere with each other.
As you can see in the shot below, Heroku is not exactly clear about how the custom domain should be added, first with, and then without 'www.' - I have tried both, but neither seemed to work with their SSL.
I also never managed to access my app from oppascentrale.nl, Do I some how have to redirect to www.oppascentrale when hitting oppascentrale.nl? And if yes, how do i set up that?

API subdomain for Heroku app, is it possible?

I am trying to build an API and I am concerned that all my resources will either not be accessible with the api.myapp.com domain or that they will "live" with the wrong uris.
I have added the CNAME for my domain name to point to my Heroku app.
(ex: browsing to www.myapp.com takes you to https://myherokuapp.heroku.com)
I would like to set up an API subdomain, so that a GET to
https://api.myapp.com takes you to https://myherokuapp.heroku.com/api/v1
The best scenario would be that a POST to https://api.myapp.com/accounts/12345 would create a new account. Is that even possible?
(I know that subdomains (eg: mysubdomain.myappname.heroku.com) are not possible with Heroku)
I believe the answer could be in three different places:
Something to do with DNS provider forwarding configs (maybe
something to do with "A" records).
Something to config in Heroku, possibly a paid add-on to handle domains/subdomains.
Handle all subdomains within my app.
If you want to differentiate between api.mydomain.com and www.mydomain.com and have different controllers for your API requests then you could certainly use Rails routes constrained to your api subdomain to handle this
constraints :subdomain => "api" do
scope :module => "api", :as => "api" do
resources :posts
end
end
which would then use the posts_controller.rb in the app/controllers/api folder of your application.
You'll then have both www.mydomain.com and api.mydomain.com added a custom domains for your application and then the routes will take care of the rest.
You might also want to look into the Grape Gem for helping build your api

When I am using google analytics to track a rails app deployed to heroku, which url do I use?

There is the initial heroku app name like something.herokuapp.com, then there is the ssl certified heroku app name like somethingelse.herokussl.com, and finally there is the actual website name www.anothername.com that is cname'd to the heroku ssl address. Which url should I ask google analytics to generate the tracking analytics code for?
I tried it with all three urls (the herokuapp, the herokussl, and the domain name I am pointing from) and they all tracked the same. So I guess it doesn't matter which one you pick
www.anothername.com
and you should add setDomainName method before trackPageview, on all pages.
_gaq.push(['_setDomainName', 'anothername.com']);

rails 3.0 subdomains and formats

I have 2 subdomains that point to one rails application. My rails application's controllers should serve both subdomains.
Lets call the subdomains www.mydomain.com and demo.mydomain.com. I want 2 to accomplish 3 things:
Make sure only some of my controllers serve www.mydomain.com and some serve both domains.
Make sure only a subset of my controllers' actions serve www.mydomain.com and some serve both domains.
Make sure users use only format :html for demo.mydomain.com (e.g. http://demo.mydomain.com/index.html) and use only formats :json/:xml for www.mydomain.com (e.g. http://www.mydomain.com/index.json).
What's the best way to accomplish both requests ?
Perhaps take a look at request routing based on subdomain
How do I route by domain / subdomain in rails
http://agilewebdevelopment.com/plugins/request_routing
where the request_routing plugin would allow you to define routing requirements that test methods/properties of the request object such as subdomain, domain, port. You can test them either against a value or with a Regexp (assuming the method returns a string).
If you're using rails 3 you could also check out subdomaining your rails site
http://railscasts.com/episodes/221-subdomains-in-rails-3
In order to get your controllers to respond differently based on subdomain, you can use a conditional based on
#host = request.host