Skip to content

Instantly share code, notes, and snippets.

@rheaton
Last active August 29, 2015 14:00
Show Gist options
  • Save rheaton/0422be6407110b92045b to your computer and use it in GitHub Desktop.
Save rheaton/0422be6407110b92045b to your computer and use it in GitHub Desktop.
development ssl (rails 4)
#...
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
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment