diff --git a/lib/serve/application.rb b/lib/serve/application.rb index ad4c1f4..5e42317 100644 --- a/lib/serve/application.rb +++ b/lib/serve/application.rb @@ -160,7 +160,7 @@ 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 + (args.delete(args.find {|a| /^\d\d\d*$/.match(a) }) || ENV['PORT'] || 4000).to_i end def extract_address(args) @@ -234,15 +234,15 @@ def extract_export(args) } end end - + def rails_script_server @rails_server_script ||= options[:root] + '/script/server' end - + def rails_app? File.file?(rails_script_server) and File.executable?(rails_script_server) end - + def run_rails_app system "#{rails_script_server} -p #{options[:port]} -b #{options[:address]} -e #{options[:environment]}" end 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..b48e246 100644 --- a/spec/application_spec.rb +++ b/spec/application_spec.rb @@ -39,6 +39,11 @@ 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 parse('-h')[:help].should be_true @@ -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