Create your self-signed certificate and put it in ~/fake_ssl (https://gist.github.com/trcarden/3295935)
Thanks to (http://www.railway.at/2013/02/12/using-ssl-in-your-local-rails-environment/)
Create your self-signed certificate and put it in ~/fake_ssl (https://gist.github.com/trcarden/3295935)
Thanks to (http://www.railway.at/2013/02/12/using-ssl-in-your-local-rails-environment/)
| #... | |
| force_ssl if: :ssl_configured? | |
| def ssl_configured? | |
| # Rails.env.production? | |
| true | |
| end | |
| #... |
| # just for development! | |
| ActionController::ForceSSL::ClassMethods.module_eval do | |
| def force_ssl(options = {}) | |
| config = Rails.application.config | |
| host = options.delete(:host) | |
| port = config.ssl_port if config.respond_to?(:ssl_port) && config.ssl_port.present? # <= this is also new | |
| before_filter(options) do | |
| if !request.ssl?# && !Rails.env.development? # commented out the exclusion of the development environment | |
| redirect_options = {protocol: 'https://', status: :moved_permanently} | |
| redirect_options.merge!(host: host) if host | |
| redirect_options.merge!(port: port) if port # <= this is also new | |
| redirect_options.merge!(params: request.query_parameters) | |
| redirect_to redirect_options | |
| end | |
| end | |
| end | |
| end |
| YourApp::Application.configure do | |
| # ... | |
| config.port = 5000 | |
| config.ssl_port = 5001 | |
| end |
| #... | |
| # gem 'unicorn' | |
| gem 'thin' | |
| #... |
| #... | |
| def ssl_configured? | |
| false | |
| end | |
| #... |
| web: thin start -p 5000 | |
| ssl: thin start -p 5001 --ssl --ssl-key-file ~/fake_ssl/server.key --ssl-cert-file ~/fake_ssl/server.crt | |
| # ... |