Move server from local scope to config

This commit is contained in:
Sdogruyol 2016-04-09 17:20:39 +03:00
parent 0eb7638b1b
commit b32099e13b
2 changed files with 8 additions and 6 deletions

View file

@ -8,12 +8,12 @@ module Kemal
config.setup config.setup
config.add_handler Kemal::RouteHandler::INSTANCE config.add_handler Kemal::RouteHandler::INSTANCE
server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers) config.server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers)
server.ssl = config.ssl config.server.ssl = config.ssl
Signal::INT.trap { Signal::INT.trap {
config.logger.write "Kemal is going to take a rest!\n" config.logger.write "Kemal is going to take a rest!\n"
server.close config.server.close
exit exit
} }
@ -31,6 +31,6 @@ module Kemal
end end
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n" config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n"
server.listen config.server.listen
end end
end end

View file

@ -2,8 +2,11 @@ module Kemal
class Config class Config
INSTANCE = Config.new INSTANCE = Config.new
HANDLERS = [] of HTTP::Handler HANDLERS = [] of HTTP::Handler
@server : HTTP::Server
property host_binding, ssl, port, env, public_folder, logging, property host_binding, ssl, port, env, public_folder, logging,
always_rescue, error_handler, serve_static, run always_rescue, error_handler, serve_static, server
def initialize def initialize
@host_binding = "0.0.0.0" @host_binding = "0.0.0.0"
@ -15,7 +18,6 @@ module Kemal
@logger = nil @logger = nil
@always_rescue = true @always_rescue = true
@error_handler = nil @error_handler = nil
@run = false
end end
def logger def logger