Rename handlers

This commit is contained in:
Sdogruyol 2016-02-03 22:08:54 +02:00
parent a4005e98be
commit 467a1b4581
12 changed files with 40 additions and 40 deletions

View file

@ -5,12 +5,12 @@ at_exit do
Kemal::CLI.new
config = Kemal.config
if config.logging
logger = Kemal::Logger.new
logger = Kemal::LogHandler.new
config.logger = logger
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n"
end
config.add_handler Kemal::StaticFileHandler.new(config.public_folder)
config.add_handler Kemal::Handler::INSTANCE
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

View file

@ -2,7 +2,7 @@ HTTP_METHODS = %w(get post put patch delete)
{% for method in HTTP_METHODS %}
def {{method.id}}(path, &block : HTTP::Server::Context -> _)
Kemal::Handler::INSTANCE.add_route({{method}}.upcase, path, &block)
Kemal::RouteHandler::INSTANCE.add_route({{method}}.upcase, path, &block)
end
{% end %}

View file

@ -1,6 +1,7 @@
require "colorize"
require "http"
class Kemal::Logger < HTTP::Handler
class Kemal::LogHandler < HTTP::Handler
INSTANCE = new
getter handler

View file

@ -34,7 +34,7 @@ end
# development: STDOUT in
# production: kemal.log
macro log(message)
Kemal::Logger::INSTANCE.write "#{{{message}}}\n" if Kemal.config.logging
Kemal::LogHandler::INSTANCE.write "#{{{message}}}\n" if Kemal.config.logging
end
# Enables / Disables logging

View file

@ -36,9 +36,8 @@ class Kemal::ParamParser
end
def parse_url_params
params = @request.url_params
if params
params.not_nil!.each do |key, value|
if params = @request.url_params
params.each do |key, value|
@params[key] = value
end
end

View file

@ -1,10 +1,10 @@
require "http/server"
require "radix"
# Kemal::Handler is the main handler which handles all the HTTP requests. Routing, parsing, rendering e.g
# Kemal::RouteHandler is the main handler which handles all the HTTP requests. Routing, parsing, rendering e.g
# are done in this handler.
class Kemal::Handler < HTTP::Handler
class Kemal::RouteHandler < HTTP::Handler
INSTANCE = new
def initialize
@ -36,7 +36,7 @@ class Kemal::Handler < HTTP::Handler
context.response.print body
return context
rescue ex
Kemal::Logger::INSTANCE.write "Exception: #{ex.to_s}\n"
Kemal::LogHandler::INSTANCE.write "Exception: #{ex.to_s}\n"
return render_500(context, ex.to_s)
end
end