Sha256: 8f2608a7055e30d30fc005b3a86e6d501442ad6a41115b02258078ab97cf70a6
Contents?: true
Size: 1.53 KB
Versions: 4
Compression:
Stored size: 1.53 KB
Contents
require 'crystal/rack/support' require 'crystal/rack/rack_app' 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 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 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
4 entries across 4 versions & 1 rubygems