From 47a48df6dff8a2c8c40b6b641d23b8dd6e0f3a9a Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Tue, 20 May 2008 21:21:42 -0600 Subject: [PATCH 1/4] Add a new option (:app_file) to determine the file to reload when in development mode. Default is $0. This is for situations where $0 isn't the Sinatra application --- lib/sinatra.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib/sinatra.rb diff --git a/lib/sinatra.rb b/lib/sinatra.rb old mode 100644 new mode 100755 index fb0af36d..d964471c --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -892,7 +892,8 @@ module Sinatra :public => root + '/public', :sessions => false, :logging => true, - :raise_errors => false + :raise_errors => false, + :app_file => $0 } load_default_options_from_command_line! @default_options @@ -1101,7 +1102,7 @@ module Sinatra load_default_configuration! @pipeline = nil @reloading = true - Kernel.load $0 + Kernel.load options.app_file @reloading = false end From c705cfde8a9244c168b78d17e2a87e00aa01bf76 Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Wed, 4 Jun 2008 17:06:08 -0600 Subject: [PATCH 2/4] Add a host option to define the ip to bind to, defaults 0.0.0.0, which is code for 'all of them' --- lib/sinatra.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) mode change 100644 => 100755 lib/sinatra.rb diff --git a/lib/sinatra.rb b/lib/sinatra.rb old mode 100644 new mode 100755 index f3544823..e7a4be87 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -108,6 +108,10 @@ module Sinatra def port application.options.port end + + def host + application.options.host + end def env application.options.env @@ -127,7 +131,7 @@ module Sinatra begin puts "== Sinatra has taken the stage on port #{port} for #{env} with backup by #{server.name}" require 'pp' - server.run(application, :Port => port) do |server| + server.run(application, {:Port => port, :Host => host}) do |server| trap(:INT) do server.stop puts "\n== Sinatra has ended his set (crowd applauds)" @@ -896,6 +900,7 @@ module Sinatra @default_options = { :run => true, :port => 4567, + :host => '0.0.0.0', :env => :development, :root => root, :views => root + '/views', From b404b0a78e26bb9ccddfe655ba45072e97c6db7d Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Sat, 7 Jun 2008 23:18:07 -0600 Subject: [PATCH 3/4] Small tweak to server method to fall back on exactly what the user sets via 'set :server, handler' if Rack::Handler::Thing doesn't exist. This lets special capitalziation cases like FastCGI, CGI, and WEBrick be handled easily. --- lib/sinatra.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index f3544823..51dbb0a3 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -118,8 +118,14 @@ module Sinatra def server options.server ||= defined?(Rack::Handler::Thin) ? "thin" : "mongrel" + # Convert the server into the actual handler name - handler = options.server.capitalize.sub(/cgi$/, 'CGI') + handler = options.server.capitalize + + # If the convenience conversion didn't get us anything, + # fall back to what the user actually set. + handler = options.server unless Rack::Handler.const_defined?(handler) + @server ||= eval("Rack::Handler::#{handler}") end From 87f8cd3937973090b84876996cc7e430bd5d744b Mon Sep 17 00:00:00 2001 From: bmizerany Date: Sun, 22 Jun 2008 17:48:31 -0700 Subject: [PATCH 4/4] converting env from command-line to symbol. [cypher] This fixes the problem when running an app with -e development --- lib/sinatra.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index d49e0a6f..b02786d6 100755 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -928,7 +928,7 @@ module Sinatra require 'optparse' OptionParser.new do |op| op.on('-p port') { |port| default_options[:port] = port } - op.on('-e env') { |env| default_options[:env] = env } + op.on('-e env') { |env| default_options[:env] = env.to_sym } op.on('-x') { default_options[:mutex] = true } op.on('-s server') { |server| default_options[:server] = server } end.parse!(ARGV.dup.select { |o| o !~ /--name/ })