Sha256: 41c3f1263b58794484eed76747ba66444463493fd72056d606c277c53478e0d4
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
module Crystal class Adapter SERVERS = %w{mongrel thin webrick} class Callback def initialize app; end def self.call env; Crystal::Adapter.call env end end class << self def build_common_app builder # CommonLogger, ShowExceptions, Lint builder.use Rack::Session::Cookie # builder.use Rack::CommonLogger builder.use Rack::MethodOverride # builder.use ShowExceptions if Crystal.config.show_exceptions? end def parse_config app, options = Rack::Builder.parse_file Crystal.config.rack_config_file app end def run app handler = detect_rack_handler handler_name = handler.name.gsub(/.*::/, '') puts " Crystal #{Crystal::VERSION} started on #{Crystal.config.port} in #{Crystal.config.environment} mode" unless handler_name =~/cgi/i handler.run app, :Host => Crystal.config.host, :Port => Crystal.config.port do |server| [:INT, :TERM].each {|sig| trap(sig){quit!(server, handler_name)}} end rescue Errno::EADDRINUSE => e puts " #{port} is taken!" end def quit!(server, handler_name) ## Use thins' hard #stop! if available, otherwise just #stop server.respond_to?(:stop!) ? server.stop! : server.stop puts "\n Crystal stopped" unless handler_name =~/cgi/i end protected def detect_rack_handler return Rack::Handler.get('mongrel') SERVERS.each do |server_name| begin return Rack::Handler.get(server_name.downcase) rescue LoadError rescue NameError end end fail " Server handler (#{SERVERS.join(', ')}) not found." end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
crystal-0.0.10 | lib/crystal/rack/adapter.rb |