mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Rename handlers
This commit is contained in:
parent
a4005e98be
commit
467a1b4581
12 changed files with 40 additions and 40 deletions
|
@ -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
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require "colorize"
|
||||
require "http"
|
||||
|
||||
class Kemal::Logger < HTTP::Handler
|
||||
class Kemal::LogHandler < HTTP::Handler
|
||||
INSTANCE = new
|
||||
getter handler
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue