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.add_handler Kemal::RouteHandler::INSTANCE
server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers)
server.ssl = config.ssl
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"
server.close
config.server.close
exit
}
@ -31,6 +31,6 @@ module Kemal
end
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

View file

@ -2,8 +2,11 @@ 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, run
always_rescue, error_handler, serve_static, server
def initialize
@host_binding = "0.0.0.0"
@ -15,7 +18,6 @@ module Kemal
@logger = nil
@always_rescue = true
@error_handler = nil
@run = false
end
def logger