Skip to content

Commit

Permalink
Config: Get environment from RAILS_ENV, too
Browse files Browse the repository at this point in the history
  - as well as from RACK_ENV
  - this is part of the effort to bring the configuration defaults from
    the puma-heroku plugin to Puma
  • Loading branch information
olleolleolle committed Oct 23, 2019
1 parent 3294c82 commit f619a6b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Strip whitespace at end of HTTP headers (#2010)
* Optimize HTTP parser for JRuby (#2012)
* Add SSL support for the control app (#2046)
* Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022)

* Bugfixes
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
$ puma -C /path/to/config
```

If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` environment variable, Puma looks for configuration at `config/puma/<environment_name>.rb`.
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma looks for configuration at `config/puma/<environment_name>.rb`.

If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:

Expand Down
2 changes: 1 addition & 1 deletion lib/puma/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def puma_default_options
:worker_shutdown_timeout => DefaultWorkerShutdownTimeout,
:remote_address => :socket,
:tag => method(:infer_tag),
:environment => -> { ENV['RACK_ENV'] || "development" },
:environment => -> { ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" },
:rackup => DefaultRackup,
:logger => STDOUT,
:persistent_timeout => Const::PERSISTENT_TIMEOUT,
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/control_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@control_auth_token = nil
@config_file = nil
@command = nil
@environment = ENV['RACK_ENV']
@environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'

@argv = argv.dup
@stdout = stdout
Expand Down
13 changes: 11 additions & 2 deletions test/test_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,20 @@ def test_load_path
$LOAD_PATH.shift
end

def test_environment
def test_environment_rack_env
ENV.delete 'RACK_ENV'

Puma::CLI.new ["--environment", @environment]

assert_equal ENV['RACK_ENV'], @environment
assert_equal @environment, ENV['RACK_ENV']
end

def test_environment_rails_env
ENV.delete 'RACK_ENV'
ENV['RAILS_ENV'] = @environment

Puma::CLI.new []

assert_equal @environment, ENV['RACK_ENV']
end
end
9 changes: 9 additions & 0 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ def test_config_files_with_rack_env
end
end

def test_config_files_with_rails_env
with_env('RAILS_ENV' => 'fake-env') do
conf = Puma::Configuration.new do
end

assert_equal ['config/puma/fake-env.rb'], conf.config_files
end
end

def test_config_files_with_specified_environment
conf = Puma::Configuration.new do
end
Expand Down

0 comments on commit f619a6b

Please sign in to comment.