Add RAILS_DEVELOPMENT_HOSTS to allow adding authorized hosts for development
Co-authored-by: Josh Abernathy <joshaber@gmail.com> Update railties/CHANGELOG.md Co-authored-by: Gannon McGibbon <gannon@hey.com> Update railties/lib/rails/application/configuration.rb Co-authored-by: Gannon McGibbon <gannon@hey.com> Use yield block to safely alter env variables Remove trailing whitespace Update railties/CHANGELOG.md wording Co-authored-by: Marivaldo Cavalheiro <marivaldo@gmail.com> Have comma separated list ignore spaces Add missing comma
This commit is contained in:
parent
35e9812dfc
commit
8c50571808
|
@ -237,9 +237,10 @@ Every Rails application comes with a standard set of middleware which it uses in
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
Rails.application.config.hosts = [
|
Rails.application.config.hosts = [
|
||||||
IPAddr.new("0.0.0.0/0"), # All IPv4 addresses.
|
IPAddr.new("0.0.0.0/0"), # All IPv4 addresses.
|
||||||
IPAddr.new("::/0"), # All IPv6 addresses.
|
IPAddr.new("::/0"), # All IPv6 addresses.
|
||||||
"localhost" # The localhost reserved domain.
|
"localhost", # The localhost reserved domain.
|
||||||
|
ENV["RAILS_DEVELOPMENT_HOSTS"] # Additional comma-separated hosts for development.
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
* Allow adding additional authorized hosts in development via `ENV['RAILS_DEVELOPMENT_HOSTS']`
|
||||||
|
|
||||||
|
*Josh Abernathy*, *Debbie Milburn*
|
||||||
|
|
||||||
* Stop generating a license for in-app plugins.
|
* Stop generating a license for in-app plugins.
|
||||||
|
|
||||||
*Gannon McGibbon*
|
*Gannon McGibbon*
|
||||||
|
|
|
@ -34,6 +34,7 @@ module Rails
|
||||||
@filter_redirect = []
|
@filter_redirect = []
|
||||||
@helpers_paths = []
|
@helpers_paths = []
|
||||||
@hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
|
@hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
|
||||||
|
@hosts.concat(ENV["RAILS_DEVELOPMENT_HOSTS"].to_s.split(",").map(&:strip)) if Rails.env.development?
|
||||||
@host_authorization = {}
|
@host_authorization = {}
|
||||||
@public_file_server = ActiveSupport::OrderedOptions.new
|
@public_file_server = ActiveSupport::OrderedOptions.new
|
||||||
@public_file_server.enabled = true
|
@public_file_server.enabled = true
|
||||||
|
|
|
@ -49,6 +49,14 @@ module ApplicationTests
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def switch_development_hosts_to(*hosts)
|
||||||
|
old_development_hosts = ENV["RAILS_DEVELOPMENT_HOSTS"]
|
||||||
|
ENV["RAILS_DEVELOPMENT_HOSTS"] = hosts.join(",")
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ENV["RAILS_DEVELOPMENT_HOSTS"] = old_development_hosts
|
||||||
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
build_app
|
build_app
|
||||||
suppress_default_config
|
suppress_default_config
|
||||||
|
@ -2933,6 +2941,44 @@ module ApplicationTests
|
||||||
assert_includes Rails.application.config.hosts, ".localhost"
|
assert_includes Rails.application.config.hosts, ".localhost"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "hosts reads multiple values from RAILS_DEVELOPMENT_HOSTS" do
|
||||||
|
host = "agoodhost.com"
|
||||||
|
another_host = "bananapants.com"
|
||||||
|
switch_development_hosts_to(host, another_host) do
|
||||||
|
app "development"
|
||||||
|
assert_includes Rails.application.config.hosts, host
|
||||||
|
assert_includes Rails.application.config.hosts, another_host
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "hosts reads multiple values from RAILS_DEVELOPMENT_HOSTS and trims white space" do
|
||||||
|
host = "agoodhost.com"
|
||||||
|
host_with_white_space = " #{host} "
|
||||||
|
another_host = "bananapants.com"
|
||||||
|
another_host_with_white_space = " #{another_host}"
|
||||||
|
switch_development_hosts_to(host_with_white_space, another_host_with_white_space) do
|
||||||
|
app "development"
|
||||||
|
assert_includes Rails.application.config.hosts, host
|
||||||
|
assert_includes Rails.application.config.hosts, another_host
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "hosts reads from RAILS_DEVELOPMENT_HOSTS" do
|
||||||
|
host = "agoodhost.com"
|
||||||
|
switch_development_hosts_to(host) do
|
||||||
|
app "development"
|
||||||
|
assert_includes Rails.application.config.hosts, host
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "hosts does not read from RAILS_DEVELOPMENT_HOSTS in production" do
|
||||||
|
host = "agoodhost.com"
|
||||||
|
switch_development_hosts_to(host) do
|
||||||
|
app "production"
|
||||||
|
assert_not_includes Rails.application.config.hosts, host
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "disable_sandbox is false by default" do
|
test "disable_sandbox is false by default" do
|
||||||
app "development"
|
app "development"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue