Have two actioncables /cable web socket servers? - ruby-on-rails

I'm getting some errors on my rails app that's doing a lot of cross domain stuff, and i'm trying to find a minor fix for this.
Is it possible to have multiple /cable url's inside the production file so that it uses both or whichever works?
example code:
config.web_socket_server_url = ['wss://example.herokuapp.com/cable', 'wss://www.example.com']
i've tried this, but unfortunately it doesn't work.

If you are using two heroku app, you can store the url of you app to a environment variable and reference that variable in you configuration. First in you terminal
heroku config:set -a YOUR_APP_NAME RAILS_HOST="YOUR_APP_URL"
then set the configuration
config.web_socket_server_url="wss://#{ENV['RAILS_HOST']}/cable"
If your second app is not a in-app case, then your should store complete url for both apps and use
config.web_socket_server_url=ENV['RAILS_HOST']

Related

Configuring SSL for an App Heroku HTTPS

Hello I am currently going through the tutorial below to add ssl to my heroku app
https://gist.github.com/shripadk/552554
so for today, I bought a domain name, set the cname to point to my heroku app
Currently my domain name is working.
I am trying to add ssl security feature to my app so secure.domainname.com works
Following the tutorial
heroku addons:add custom_domains:basic
I got an error
add ons not found
I can't find this add on on heroku as well. but I searched this command through stackoverflow and its suppose to exist?
I got the same error with this command
heroku addons:add ssl:hostname
but it also said adds on not found, later I found this same add on heroku but its with a different command.
This is the part that I don't get on the tutorial
After adding the ssl add on
This will add a $20/month (as of the time of this writing) fee to your Heroku bill for SSL.
VI: Setting up your DNS to work with Heroku Hostname SSL
You should recieve an email from heroku within a few minutes of adding the ssl:hostname addon. You need to add a CNAME record to your DNS that points to the AWS host in the email you receive. This should be pretty self explanatory, but if you have any questions, search for 'adding a CNAME record' in Google and you'll see lots of good guides.
Test that 'host secure.yourdomain.com' outputs 'something.amazonaws.com'. If it does, you're all set.
You should now be able to go to 'https://secure.yourdomain.com' and not see any errors or security warnings.
What is going on behind the scenes
When a user visits your site using 'http://secure.yourdomain.com', they're hitting your GoDaddy CNAME record, which points to an 'something.amazonaws.com' address which effectively routes the request to Heroku's grid, and a secure connection gets established from there following the standard SSL handshake process.
I didn't get an email, neither does appname.herokussl.com exist?
Am I suppose to use Zerigo DNS? for anything, its mentioned once in the top of the tutorial but not anywhere else?
From reading the comments, someone got a problem with the end part as well.
Thanks!
I followed this tutorial for both heroku and for my own server setup and when trying to setup on heroku for the first time I did not do it correctly so I will explain some of the important steps when setting up ssl on heroku.
Use OpenSSL to generate a new self-signed certificate ('host.csr') using the host key we just created. This is what you'll be sending to
GoDaddy to model your new SSL after.
At the step above make sure you fill in the information correctly and also make sure your common name matches your ssl certificate name.
2. Combine 'secure.yourdomain.com.crt' and 'host.key':
You will need to combine your ssl keys. If you're using godaddy there are 2 files included name gd_bundle.crt and secure.yourdomain.com. Upon during the tutorial you will generate about 5-6 files in which you will only use 1.
Remove pass phrase from the public key certificate (required by Heroku)
In order for heroku to read your ssl cert you will need to remove all passwords on the certs so make sure the passwords are removed. There will be two files depending on how you have combined them with the extensions .pem and .key (The updated ones not the ones you started with).
You've most likely added the domain and subdomain so now through the command line run
heroku ssl:add ../ssl-cert/public.pem ../ssl-cert/private.key
Remember get the path of the newly updated files. Also when editing the files and copying over keys make sure there are no white spaces in between keys. Let me know if this helps.

Ruby on Rails Heroku set first part of domain

I have developed a RoR app. I would like to update it to handle more than one customer. For instance, one customer might use ame.requestsys.com and another would be slc.requestsys.com.
Currently on Heroku, I have requestsys.com and www.requestsys.com
I was told that I need to have *.requestsys.com --> is that correct?
If yes, why won't Heroku let me add it?
Thanks
From the command line in the directory of your app do:
$ heroku domains:add *.requestsys.com
You can also do it from the heroku dashboard.
Then setup a CNAME in your DNS accordingly to point to yourapp.herokuapp.com
Try this guide for more info: https://devcenter.heroku.com/articles/custom-domains#wildcard-domains.
Basically what you wanna do is a multitenant app, there are a couple railscasts on the subject:
http://railscasts.com/episodes?search=multitenancy
But thats beyond the scope of the question.

Development workflow for Heroku?

I have used Heroku to push up my already coded Rails applications.
But now I wonder how the workflow would look like if I start coding a new Rails application from scratch.
For example if I use their addons (MongoHQ, Redis, Websolr, Sendgrid etc) in my application code, then I guess I shouldn't install MongoDB, Redis, Solr, Mail server etc in my local environment since they won't work with my code, correct?
So that means I have to push my app up to the Heroku platform to be able to run it in the web browser. That means, after a change of lines I have to commit and push it up.
If I'm correct, isn't this time-consuming since before I just changed the code and I could see the results in the browser immediately. Now I have to push for every change I want to see in browser.
You can install all of these locally - you should only need to specify different configurations when you are running in production rather than development.
For example, with Websolr, adding the following line in your initializer:
Sunspot.config.solr.url = ENV['WEBSOLR_URL'] if ENV['WEBSOLR_URL']
Will allow it to work both locally and on Heroku. See the docs for more information.
I can't tell for all addons, but the ones I used have very good fall-back mechanism for local deployment in development mode.
For example, Sendgrid will detect when you're using ActionMailer and send emails for you. You don't have to configure or call anything in your code. Locally you send emails as before (through sendmail or smtp server)
Same with exceptional (although you can invoke its API directly).
MongoHQ... Isn't it supposed to be replacement for PostgreSQL? Then, you should not care in most cases, just like you don't care about PostgreSQL running and not MySQL.

Rails Under Construction Page

I know this may seem trivial to some, other won't see the point, however - for me this would be great:
I am trying to work out how to quickly and efficiently commit updates to my Rails app, switch to an under construction style page while I restart the rails app and then test the changes, then when I am happy, switch back to the live public version.
At the moment, I follow the following pattern:
1, make changes to app
2, commit using Versions App for Mac to BeanstalkApp
3, deploy revision from BeanstalkApp to server
4, login to server and restart apache
5, wait a few seconds and then start to double check everything is A-OK
If it helps, I am using Passenger on a Turnkey Rails image VPS.
Thanks in advance for any advice, etc.
Thanks,
Danny
You have a few options:
Create a subdomain for 'testing' and deploy it to your production server and when it's vetted you can push it to your production code location.
You'll need to be able to add a subdomain to your DNS record to point to the same IP address as your main production server. You'll then also need to add a new VirtualHost with ServerName subdomain.host.com and DocumentRoot /data/host.com/testing/public so that it loads that code.
Using Passenger create a subfolder app. See section 3.2 of http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_ruby_on_rails_application to see how to add RailsBaseURI directives to enable separate sites in subdirectories. This means you deploy your code to another directory and create the simlink.
I have personally done BOTH approaches. I prefer approach #1 but it's personal preference and the level of access you have to your hosts.

How can I manage a different setup for my Ruby on Rails application dependent on production or development?

I am trying to deploy my first rails app and struggling a bit. My plan is to initially host it on a heroku free account to get a feel for live deployments and do some production testing. Eventually I might move it to a VPS.
I use git and do not use Capistrano at the moment.
Heroku primarily uses git, which is fine, but git manages the entire project state not files. So I have issues managing configuration files that are different from production to development, for example captcha keys in the environment.rb or goolge js api keys.
So what I did was to..
1 - Take the environment specific configuration out of the enviornment.rb and put it in the development.rb and production.rb. Created a branch called dev where I do my development and then merge it with master and push master to the production heroku remote.
This all works ok, but wondering if there is a better way to do it.
The other massive problem is I might have to use different gems in dev and in herouku. For example, I use ThinkingSphinix for search in dev, but Heroku I have to use acts_as_solr, which means my "Article.search call in the controller, will have to be Article.find_by_solr in production. This can become messy very fast.
What's the best way to deal with this kind of situation?
Thanks
For non-sensitive keys such as Google's JS API key etc., I found this RailsCasts episode very helpful.
Just created a config file under config/ and store your development settings in there.
# /config/google.yml
development:
google:
js:
key: 123456
test:
google:
js:
key: 345678
production:
google:
js:
key: 567890
Then create an initializer inside config/initializers/ that will parse the yaml and create an object which can be used without worrying about the current environment.
# /config/initializers/google.rb
GOOGLE_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/google.yml")[RAILS_ENV]
The environment variable RAILS_ENV refers to the current environment, so on application startup it picks up the current type, and you can refer to the settings in your code through GOOGLE_CONFIG:
<script type="text/javascript" src="http://www.google.com/jsapi?key=<%= GOOGLE_CONFIG['js']['key'] %>"></script>
For the latter issue, where code itself differs from environment to environment, I believe Capistrano would be a better solution.
For values that you want to keep different between environments, Heroku offers config vars.
As for using one indexing program in production and another in development, that's a bad idea, and will make things way messier than they need to be. Either start using Solr locally, or set up a Thinking Sphinx instance in EC2 yourself, and have your dynos connect to it.
I would suggest that it is very unwise to have different code in development and production.
Your development, test and production environments should be as similar as possible.
In fact, I would go so far as to say the entire point of the different environments is to simply provide an easy system for allowing minor configuration changes between setups. Different databases, different API parameters, different aching options, but the core system MUST be the same.
The the issue you will face is doubling your development effort. You still have to write the code. So in the search example you provide above, you will have to develop and test twice - once for the Solr production system and once for you local Sphinx, then you need to be able to switch and test between the two approaches in all of your environments to ensure test coverage and functionality.

Resources