From 65d0af5b5f953c9c263d0e4c657517c4d64567ce Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Sat, 9 Apr 2016 17:33:17 +0300 Subject: [PATCH] Update config to use uninitialized server --- src/kemal.cr | 36 +++++++++++++++++++----------------- src/kemal/config.cr | 3 +-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/kemal.cr b/src/kemal.cr index c239202..a071609 100644 --- a/src/kemal.cr +++ b/src/kemal.cr @@ -11,26 +11,28 @@ module Kemal config.server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers) config.server.ssl = config.ssl - Signal::INT.trap { - config.logger.write "Kemal is going to take a rest!\n" - config.server.close - exit - } + unless config.env == "test" + Signal::INT.trap { + config.logger.write "Kemal is going to take a rest!\n" + config.server.close + exit + } - # This route serves the built-in images for not_found and exceptions. - get "/__kemal__/:image" do |env| - image = env.params.url["image"] - file_path = File.expand_path("libs/kemal/images/#{image}", Dir.current) - if File.exists? file_path - env.response.headers.add "Content-Type", "application/octet-stream" - env.response.content_length = File.size(file_path) - File.open(file_path) do |file| - IO.copy(file, env.response) + # This route serves the built-in images for not_found and exceptions. + get "/__kemal__/:image" do |env| + image = env.params.url["image"] + file_path = File.expand_path("libs/kemal/images/#{image}", Dir.current) + if File.exists? file_path + env.response.headers.add "Content-Type", "application/octet-stream" + env.response.content_length = File.size(file_path) + File.open(file_path) do |file| + IO.copy(file, env.response) + end end end - end - config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n" - config.server.listen + config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n" + config.server.listen + end end end diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 724734c..3e57858 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -2,8 +2,6 @@ module Kemal class Config INSTANCE = Config.new HANDLERS = [] of HTTP::Handler - - @server : HTTP::Server property host_binding, ssl, port, env, public_folder, logging, always_rescue, error_handler, serve_static, server @@ -18,6 +16,7 @@ module Kemal @logger = nil @always_rescue = true @error_handler = nil + @server = uninitialized HTTP::Server end def logger