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

Use the PORT environment variable for rails server #21267

Merged
merged 1 commit into from Aug 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,7 @@
* `rails server` will now honour the `PORT` environment variable

*David Cornu*

* Plugins generated using `rails plugin new` are now generated with the
version number set to 0.1.0.

Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/commands/server.rb
Expand Up @@ -86,7 +86,7 @@ def middleware

def default_options
super.merge({
Port: 3000,
Port: ENV.fetch('PORT', 3000).to_i,
DoNotReverseLookup: true,
environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
daemonize: false,
Expand Down
7 changes: 7 additions & 0 deletions railties/test/commands/server_test.rb
Expand Up @@ -44,6 +44,13 @@ def test_environment_with_rack_env
end
end

def test_environment_with_port
switch_env "PORT", "1234" do
server = Rails::Server.new
assert_equal 1234, server.options[:Port]
end
end

def test_caching_without_option
args = []
options = Rails::Server::Options.new.parse!(args)
Expand Down