Skip to content

Commit

Permalink
extracted Sinatra::MoreServer from BigBand
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Feb 12, 2010
0 parents commit d605cb7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/sinatra/more_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "sinatra/base"

module Sinatra
# Adds more servers to Sinatra::Base#run! (currently unicorn and rainbows).
module MoreServer
autoload :Unicorn, "big_band/more_server/unicorn"
autoload :Rainbows, "big_band/more_server/rainbows"
def self.registered(klass)
Rack::Handler.register "unicorn", "BigBand::MoreServer::Unicorn"
Rack::Handler.register "rainbows", "BigBand::MoreServer::Rainbows"
klass.server += "rainbows", "unicorn"
end
end

register MoreServer
end
13 changes: 13 additions & 0 deletions lib/sinatra/more_server/rainbows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "sinatra/more_server/unicorn"
require "rainbows"

class Sinatra
module MoreServer
# Rack Handler to use Rainbows for Sinatra::Base.run!
module Rainbows
def self.run(app, options = {})
Sinatra::MoreServer::Unicorn.run app, options.merge(:Backend => ::Rainbows)
end
end
end
end
27 changes: 27 additions & 0 deletions lib/sinatra/more_server/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "sinatra/base"
require "unicorn"
require "rack/content_length"
require "rack/chunked"

class Sinatra
module MoreServer
# Rack Handler to use Unicorn for Sinatra::Base.run!
module Unicorn
def self.run(app, options={})
app = Rack::Builder.new do
# TODO: env dependend stuff.
use Rack::CommonLogger, $stderr
use Rack::ShowExceptions
run app
end.to_app
options[:Backend] ||= ::Unicorn
options[:Host] ||= ::Unicorn::Const::DEFAULT_HOST
options[:Port] ||= ::Unicorn::Const::DEFAULT_PORT
options[:listeners] = ["#{options.delete :Host}:#{options.delete :Port}"]
server = options.delete(:Backend)::HttpServer.new app, options
yield server if block_given?
server.start.join
end
end
end
end

0 comments on commit d605cb7

Please sign in to comment.