Sha256: 4df197c36fb3035dc6563eb9751c412e1ec2949eaa8e16163245b1620b63b122
Contents?: true
Size: 1.97 KB
Versions: 3
Compression:
Stored size: 1.97 KB
Contents
module Crystal class RackAdapter SERVERS = %w{mongrel thin webrick} # class Callback # def initialize app; end # def self.call env; Crystal::Adapter.call env end # end class << self inject( :logger => :logger, :config => :config ) def build_common_app builder = nil, &block if block @build_common_app = block else unless @build_common_app raise "Common App not defined! Use profiles (like crystal/profiles/web), define it by yourself or use your own configuration!" end @build_common_app.call builder end end def parse_config app, options = Rack::Builder.parse_file 'config.ru' app end def run app handler = detect_rack_handler handler_name = handler.name.gsub(/.*::/, '') # unless handler_name =~/cgi/i logger.info "Crystal #{Crystal::VERSION} started on #{config.port!} in :#{config.environment!} mode (at #{Time.now.to_s})\n\n" handler.run app, :Host => config.host!, :Port => config.port! do |server| [:INT, :TERM].each {|sig| trap(sig){quit!(server, handler_name)}} end rescue Errno::EADDRINUSE => e logger.error "Port #{config.port!} 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 "\nCrystal 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
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
crystal-0.0.13 | lib/crystal/http/support/rack/rack_adapter.rb |
crystal-0.0.12 | lib/crystal/http/support/rack/rack_adapter.rb |
crystal_ext-0.0.11 | lib/crystal/http/support/rack/rack_adapter.rb |