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
|
2016-01-13 20:22:34 +00:00
|
|
|
Kemal::CLI.new
|
2015-10-23 18:33:26 +00:00
|
|
|
config = Kemal.config
|
2015-11-19 18:54:58 +00:00
|
|
|
logger = Kemal::Logger.new
|
|
|
|
config.add_handler logger
|
2015-12-12 18:27:46 +00:00
|
|
|
config.add_handler Kemal::StaticFileHandler.new(config.public_folder)
|
2015-11-12 20:48:22 +00:00
|
|
|
config.add_handler Kemal::Handler::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
|
2016-01-03 14:04:11 +00:00
|
|
|
logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n"
|
2015-11-19 18:54:58 +00:00
|
|
|
|
|
|
|
Signal::INT.trap {
|
2015-11-22 17:02:09 +00:00
|
|
|
logger.write "Kemal is going to take a rest!\n"
|
2015-11-19 18:54:58 +00:00
|
|
|
logger.handler.close
|
|
|
|
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["image"]
|
2015-12-24 15:25:00 +00:00
|
|
|
file_path = File.expand_path("libs/kemal/images/#{image}", Dir.current)
|
2015-11-28 10:39:58 +00:00
|
|
|
env.add_header "Content-Type", "application/octet-stream"
|
2016-01-13 20:22:34 +00:00
|
|
|
File.read(file_path) if File.exists? file_path
|
2015-11-28 10:39:58 +00:00
|
|
|
end
|
|
|
|
|
2015-12-19 08:00:29 +00:00
|
|
|
server.listen
|
2014-06-11 23:41:02 +00:00
|
|
|
end
|