]> cat aescling's git repositories - mastodon.git/commitdiff
Return force_ssl to the controller (#2380)
authorMatt Jankowski <mjankowski@thoughtbot.com>
Mon, 24 Apr 2017 00:44:05 +0000 (20:44 -0400)
committerEugen <eugen@zeonfederated.com>
Mon, 24 Apr 2017 00:44:05 +0000 (02:44 +0200)
app/controllers/application_controller.rb
config/environments/production.rb

index ad2be71eec9b8e8a1f311498195d3513ff840851..2918954576d44b0ae95c68e0777f451085058d85 100644 (file)
@@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
   # For APIs, you may want to use :null_session instead.
   protect_from_forgery with: :exception
 
+  force_ssl if: :https_enabled?
+
   include Localized
 
   helper_method :current_account
@@ -24,6 +26,10 @@ class ApplicationController < ActionController::Base
 
   private
 
+  def https_enabled?
+    Rails.env.production? && ENV['LOCAL_HTTPS'] == 'true'
+  end
+
   def store_current_location
     store_location_for(:user, request.url)
   end
index 80933eda96849112bea1266968f6963f8bfa4649..fde69dc70892724ed4152094f3dc09e7e1c41c4d 100644 (file)
@@ -35,14 +35,6 @@ Rails.application.configure do
   # Allow to specify public IP of reverse proxy if it's needed
   config.action_dispatch.trusted_proxies = [IPAddr.new(ENV['TRUSTED_PROXY_IP'])] unless ENV['TRUSTED_PROXY_IP'].blank?
 
-  # When LOCAL_HTTPS is set, force traffic over SSL
-  config.force_ssl = (ENV['LOCAL_HTTPS'] == 'true')
-
-  # When ENABLE_HSTS is also set, turn on Strict-Transport-Security
-  config.ssl_options = {
-    hsts: (ENV['ENABLE_HSTS'] == 'true')
-  }
-
   # By default, use the lowest log level to ensure availability of diagnostic information
   # when problems arise.
   config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info').to_sym