Skip to content

Commit

Permalink
refactor: middleware_enabled_rails_envs to
Browse files Browse the repository at this point in the history
middleware_enabled
  • Loading branch information
aki77 committed Nov 8, 2023
1 parent 4101c7a commit 8fcd0c2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/sg_fargate_rails/config.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module SgFargateRails
class Config
attr_reader :proxy_ip_addresses
attr_accessor :middleware_enabled_rails_envs
attr_accessor :middleware_enabled

# NOTE: good_jobダッシュボードへのアクセスをproxy経由のアクセスに制限するかどうか
attr_accessor :restrict_access_to_good_job_dashboard

def initialize
self.proxy_ip_addresses = ENV['SG_PROXY_IP_ADDRESSES']
self.restrict_access_to_good_job_dashboard = Rails.env.production?
self.middleware_enabled_rails_envs = %w[production staging]
self.middleware_enabled = !Rails.env.development? && !Rails.env.test?
end

def proxy_ip_addresses=(ip_addresses)
Expand Down
2 changes: 1 addition & 1 deletion lib/sg_fargate_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Railtie < ::Rails::Railtie
end

initializer :initialize_sg_fargate_rails, after: :load_config_initializers do |app|
if SgFargateRails.config.middleware_enabled_rails_envs.include?(Rails.env)
if SgFargateRails.config.middleware_enabled
app.config.middleware.insert 0, SgFargateRails::AdjustCloudfrontHeaders
app.config.middleware.insert 1, SgFargateRails::Healthcheck
app.config.middleware.swap ActionDispatch::RemoteIp, SgFargateRails::RemoteIp, app.config.action_dispatch.ip_spoofing_check, app.config.action_dispatch.trusted_proxies
Expand Down

0 comments on commit 8fcd0c2

Please sign in to comment.