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 10, 2019
1 parent d41cb68 commit 5ce7365
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -3,6 +3,7 @@
* Features
* Strip whitespace at end of HTTP headers (#2010)
* Optimize HTTP parser for JRuby (#2012)
* 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
Expand Up @@ -219,7 +219,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
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
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'] || "development"
@environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development"

@argv = argv.dup
@stdout = stdout
Expand Down
9 changes: 9 additions & 0 deletions test/test_config.rb
Expand Up @@ -246,6 +246,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 5ce7365

Please sign in to comment.