mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Update config to use uninitialized server
This commit is contained in:
parent
b32099e13b
commit
65d0af5b5f
2 changed files with 20 additions and 19 deletions
36
src/kemal.cr
36
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 = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers)
|
||||||
config.server.ssl = config.ssl
|
config.server.ssl = config.ssl
|
||||||
|
|
||||||
Signal::INT.trap {
|
unless config.env == "test"
|
||||||
config.logger.write "Kemal is going to take a rest!\n"
|
Signal::INT.trap {
|
||||||
config.server.close
|
config.logger.write "Kemal is going to take a rest!\n"
|
||||||
exit
|
config.server.close
|
||||||
}
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# This route serves the built-in images for not_found and exceptions.
|
# This route serves the built-in images for not_found and exceptions.
|
||||||
get "/__kemal__/:image" do |env|
|
get "/__kemal__/:image" do |env|
|
||||||
image = env.params.url["image"]
|
image = env.params.url["image"]
|
||||||
file_path = File.expand_path("libs/kemal/images/#{image}", Dir.current)
|
file_path = File.expand_path("libs/kemal/images/#{image}", Dir.current)
|
||||||
if File.exists? file_path
|
if File.exists? file_path
|
||||||
env.response.headers.add "Content-Type", "application/octet-stream"
|
env.response.headers.add "Content-Type", "application/octet-stream"
|
||||||
env.response.content_length = File.size(file_path)
|
env.response.content_length = File.size(file_path)
|
||||||
File.open(file_path) do |file|
|
File.open(file_path) do |file|
|
||||||
IO.copy(file, env.response)
|
IO.copy(file, env.response)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
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"
|
||||||
config.server.listen
|
config.server.listen
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,8 +2,6 @@ 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, server
|
always_rescue, error_handler, serve_static, server
|
||||||
|
@ -18,6 +16,7 @@ module Kemal
|
||||||
@logger = nil
|
@logger = nil
|
||||||
@always_rescue = true
|
@always_rescue = true
|
||||||
@error_handler = nil
|
@error_handler = nil
|
||||||
|
@server = uninitialized HTTP::Server
|
||||||
end
|
end
|
||||||
|
|
||||||
def logger
|
def logger
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue