Skip to content

Commit

Permalink
Merge commit 'bmizerany/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cypher committed Jun 25, 2008
2 parents 92aa941 + 87f8cd3 commit d22de90
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/sinatra.rb 100644 → 100755
Expand Up @@ -108,6 +108,10 @@ def application=(app)
def port
application.options.port
end

def host
application.options.host
end

def env
application.options.env
Expand All @@ -118,17 +122,22 @@ def env

def server
options.server ||= defined?(Rack::Handler::Thin) ? "thin" : "mongrel"

# Convert the server into the actual handler name
# Special cases for [Fast]CGI and WEBrick
handler = options.server.capitalize.sub(/cgi$/, 'CGI').sub(/^Webrick$/, 'WEBrick')
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

def run
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)"
Expand Down Expand Up @@ -897,6 +906,7 @@ def self.default_options
@default_options = {
:run => true,
:port => 4567,
:host => '0.0.0.0',
:env => :development,
:root => root,
:views => root + '/views',
Expand All @@ -918,7 +928,7 @@ def self.load_default_options_from_command_line! #:nodoc:
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/ })
Expand Down Expand Up @@ -1113,7 +1123,7 @@ def reload!
load_default_configuration!
@pipeline = nil
@reloading = true
Kernel.load Sinatra.options.app_file
Kernel.load options.app_file
@reloading = false
end

Expand Down

0 comments on commit d22de90

Please sign in to comment.