kemal/src/kemal.cr

35 lines
1.0 KiB
Crystal
Raw Normal View History

2015-10-23 19:48:30 +00:00
require "./kemal/*"
2015-12-27 09:59:07 +00:00
require "./kemal/middleware/*"
2014-06-11 23:41:02 +00:00
2014-07-30 22:17:53 +00:00
at_exit do
Kemal::CLI.new
2015-10-23 18:33:26 +00:00
config = Kemal.config
2016-02-15 07:01:41 +00:00
config.setup
2016-02-03 20:08:54 +00:00
config.add_handler Kemal::RouteHandler::INSTANCE
2015-11-16 21:55:02 +00:00
2016-01-03 14:04:11 +00:00
server = HTTP::Server.new(config.host_binding.not_nil!.to_slice, config.port, config.handlers)
2014-07-30 22:17:53 +00:00
server.ssl = config.ssl
2015-11-19 18:54:58 +00:00
Signal::INT.trap {
2016-02-12 12:11:21 +00:00
config.logger.write "Kemal is going to take a rest!\n"
2015-11-19 18:54:58 +00:00
server.close
exit
}
2015-11-28 10:39:58 +00:00
# This route serves the built-in images for not_found and exceptions.
get "/__kemal__/:image" do |env|
image = env.params.url["image"]
2015-12-24 15:25:00 +00:00
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
2015-11-28 10:39:58 +00:00
end
2016-02-15 07:01:41 +00:00
2016-02-14 13:15:28 +00:00
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n"
2015-12-19 08:00:29 +00:00
server.listen
2014-06-11 23:41:02 +00:00
end