Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sdogruyol
committed
Mar 19, 2016
1 parent
664673f
commit fd904cd
Showing
2 changed files
with
32 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,40 @@ | ||
require "./kemal/*" | ||
require "./kemal/middleware/*" | ||
|
||
at_exit do | ||
Kemal::CLI.new | ||
config = Kemal.config | ||
config.setup | ||
config.add_handler Kemal::RouteHandler::INSTANCE | ||
module Kemal | ||
def self.run | ||
Kemal::CLI.new | ||
config = Kemal.config | ||
config.setup | ||
config.add_handler Kemal::RouteHandler::INSTANCE | ||
|
||
server = HTTP::Server.new(config.host_binding.not_nil!.to_slice, config.port, config.handlers) | ||
server.ssl = config.ssl | ||
server = HTTP::Server.new(config.host_binding.not_nil!.to_slice, config.port, config.handlers) | ||
server.ssl = config.ssl | ||
|
||
Signal::INT.trap { | ||
config.logger.write "Kemal is going to take a rest!\n" | ||
server.close | ||
exit | ||
} | ||
Signal::INT.trap { | ||
config.logger.write "Kemal is going to take a rest!\n" | ||
server.close | ||
exit | ||
} | ||
|
||
# This route serves the built-in images for not_found and exceptions. | ||
get "/__kemal__/:image" do |env| | ||
image = env.params.url["image"] | ||
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) | ||
# This route serves the built-in images for not_found and exceptions. | ||
get "/__kemal__/:image" do |env| | ||
image = env.params.url["image"] | ||
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 | ||
end | ||
|
||
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n" | ||
server.listen | ||
end | ||
end | ||
|
||
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n" | ||
server.listen | ||
at_exit do | ||
Kemal.run if Kemal.config.run | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters