Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Logic For Allowing Multiple Hosts #972

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Changed

- Refactor Logic For Allowing Multiple Hosts [#972](https://github.com/portagenetwork/roadmap/pull/972)

## [4.1.1+portage-4.2.3] - 2024-11-20

### Added
Expand Down
8 changes: 1 addition & 7 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'syslog/logger'

# rubocop:disable Metrics/BlockLength
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down Expand Up @@ -97,12 +96,7 @@
# This allows us to define the hostname and add it to the whitelist. If you attempt
# to access the site and receive a 'Blocked host' error then you will need to
# set this environment variable
# Convert comma-separated string to array
dmproadmap_hosts = Rails.application.secrets.dmproadmap_host.to_s.split(',').map(&:strip)
dmproadmap_hosts.each do |host|
config.hosts << host
end
# Handled by config/initializers/allowed_hosts.rb
end
# rubocop:enable Metrics/BlockLength
# Used by Rails' routes url_helpers (typically when including a link in an email)
Rails.application.routes.default_url_options[:host] = Rails.application.secrets.dmproadmap_host
6 changes: 0 additions & 6 deletions config/environments/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@
authentication: Rails.application.secrets.smtp_authentication || 'plain',
enable_starttls_auto: true
}

# Convert comma-separated string to array
dmproadmap_hosts = Rails.application.secrets.dmproadmap_host.to_s.split(',').map(&:strip)
dmproadmap_hosts.each do |host|
config.hosts << host
end
end
# Fix JSON Download Error
Rails.application.routes.default_url_options[:host] = Rails.application.secrets.dmproadmap_host
5 changes: 0 additions & 5 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,5 @@
authentication: Rails.application.secrets.smtp_authentication || 'plain',
enable_starttls_auto: true
}
# Convert comma-separated string to array
dmproadmap_hosts = Rails.application.secrets.dmproadmap_host.to_s.split(',').map(&:strip)
dmproadmap_hosts.each do |host|
config.hosts << host
end
end
Rails.application.routes.default_url_options[:host] = Rails.application.secrets.dmproadmap_host
16 changes: 16 additions & 0 deletions config/initializers/allowed_hosts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# This initializer sets the allowed hosts for the app configuration.
# https://guides.rubyonrails.org/configuring.html#actiondispatch-hostauthorization
module AllowedHosts
def self.add_allowed_hosts(config)
# Convert comma-separated string to array
hosts = Rails.application.secrets.dmproadmap_host.to_s.split(',').map(&:strip)
hosts.each do |host|
config.hosts << host
end
end
end

# Add the allowed hosts (unless in development or test environment)
AllowedHosts.add_allowed_hosts(Rails.application.config) unless Rails.env.in?(%w[development test])