Permalink
Browse files

extracted Sinatra::MoreServer from BigBand

  • Loading branch information...
0 parents commit d605cb7ff3076b5ee4a3b3944ac6404ebf315a3d @rkh committed Feb 12, 2010
Showing with 56 additions and 0 deletions.
  1. +16 −0 lib/sinatra/more_server.rb
  2. +13 −0 lib/sinatra/more_server/rainbows.rb
  3. +27 −0 lib/sinatra/more_server/unicorn.rb
@@ -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
@@ -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
@@ -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.