From 8fcd0c2eb9e46dcea5e69da172829dd9eab04489 Mon Sep 17 00:00:00 2001 From: aki Date: Wed, 8 Nov 2023 09:53:49 +0900 Subject: [PATCH] refactor: middleware_enabled_rails_envs to middleware_enabled --- lib/sg_fargate_rails/config.rb | 4 ++-- lib/sg_fargate_rails/railtie.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sg_fargate_rails/config.rb b/lib/sg_fargate_rails/config.rb index 597606a..5739e67 100644 --- a/lib/sg_fargate_rails/config.rb +++ b/lib/sg_fargate_rails/config.rb @@ -1,7 +1,7 @@ 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 @@ -9,7 +9,7 @@ class Config 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) diff --git a/lib/sg_fargate_rails/railtie.rb b/lib/sg_fargate_rails/railtie.rb index 19af7e1..53d3439 100644 --- a/lib/sg_fargate_rails/railtie.rb +++ b/lib/sg_fargate_rails/railtie.rb @@ -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