diff --git a/lib/serve/application.rb b/lib/serve/application.rb index ad4c1f4..6d588eb 100644 --- a/lib/serve/application.rb +++ b/lib/serve/application.rb @@ -160,7 +160,8 @@ def extract_environment(args) end def extract_port(args) - (args.delete(args.find {|a| /^\d\d\d*$/.match(a) }) || ((rails_app? or rack_app?) ? 3000 : 4000)).to_i + default_port = rails_app? ? 3000 : 4000 + (args.delete(args.find {|a| /^\d\d\d*$/.match(a) }) || ENV['PORT'] || default_port).to_i end def extract_address(args) diff --git a/lib/serve/bootstrap/config.ru b/lib/serve/bootstrap/config.ru index 82dd519..0310065 100644 --- a/lib/serve/bootstrap/config.ru +++ b/lib/serve/bootstrap/config.ru @@ -1,5 +1,3 @@ -#\ -p 4000 - require 'rubygems' require 'bundler' begin @@ -44,4 +42,4 @@ else Serve::RackAdapter.new(root + '/views'), Rack::Directory.new(root + '/public') ]) -end \ No newline at end of file +end diff --git a/spec/application_spec.rb b/spec/application_spec.rb index b176da1..88f1dc7 100644 --- a/spec/application_spec.rb +++ b/spec/application_spec.rb @@ -38,6 +38,11 @@ it "with the port, address, and protocol" do parse('http://1.1.1.1:2000').should == @options.update(:address => "1.1.1.1", :port=>2000) end + + it "with port set in ENV" do + ENV["PORT"] = "4321" + parse[:port].should == 4321 + end it "help" do parse('')[:help].should be_false @@ -150,4 +155,4 @@ def parse(*args) end -end \ No newline at end of file +end diff --git a/website/config.ru b/website/config.ru index 7f8dfad..ce48a2a 100644 --- a/website/config.ru +++ b/website/config.ru @@ -1,5 +1,3 @@ -#\ -p 4000 - require 'rubygems' require 'bundler' begin