mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Improve kemal.cr
This commit is contained in:
parent
fe10d210c3
commit
092f5a2e49
13 changed files with 13 additions and 24 deletions
|
@ -28,5 +28,4 @@ describe "Config" do
|
|||
config.add_handler CustomTestHandler.new
|
||||
config.handlers.size.should eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -27,7 +27,6 @@ describe "Macros" do
|
|||
logging false
|
||||
Kemal.config.logging.should eq false
|
||||
end
|
||||
|
||||
it "sets a custom logger" do
|
||||
config = Kemal::Config::INSTANCE
|
||||
logger CustomLogHandler.new("production")
|
||||
|
|
|
@ -5,9 +5,8 @@ at_exit do
|
|||
Kemal::CLI.new
|
||||
config = Kemal.config
|
||||
config.setup_logging
|
||||
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n"
|
||||
config.add_handler Kemal::StaticFileHandler.new(config.public_folder)
|
||||
config.setup_error_handler
|
||||
config.add_handler Kemal::StaticFileHandler.new(config.public_folder)
|
||||
config.add_handler Kemal::RouteHandler::INSTANCE
|
||||
|
||||
server = HTTP::Server.new(config.host_binding.not_nil!.to_slice, config.port, config.handlers)
|
||||
|
@ -32,5 +31,6 @@ at_exit do
|
|||
end
|
||||
end
|
||||
|
||||
config.logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://#{config.host_binding}:#{config.port}\n"
|
||||
server.listen
|
||||
end
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require "http"
|
||||
|
||||
class Kemal::BaseLogHandler < HTTP::Handler
|
||||
|
||||
def initialize(@env)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,5 +12,4 @@ class Kemal::CommonErrorHandler < HTTP::Handler
|
|||
return render_500(context, ex.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@ require "colorize"
|
|||
require "http"
|
||||
|
||||
class Kemal::CommonLogHandler < Kemal::BaseLogHandler
|
||||
# INSTANCE = new
|
||||
getter handler
|
||||
|
||||
def initialize(@env)
|
||||
|
|
|
@ -55,7 +55,6 @@ module Kemal
|
|||
HANDLERS << @error_handler.not_nil!
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.config
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
module Kemal::Exceptions
|
||||
|
||||
class RouteNotFound < Exception
|
||||
def initialize(context)
|
||||
super "Requested path: '#{context.request.override_method as String}:#{context.request.path}' was not found."
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -43,8 +43,7 @@ macro logging(status)
|
|||
end
|
||||
|
||||
macro logger(logger)
|
||||
|
||||
Kemal.config.logger = {{logger}}
|
||||
Kemal.config.add_handler {{logger}}
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -45,15 +45,14 @@ module Kemal::Middleware
|
|||
super "An after-filter is already defined for path: '#{path}'."
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Block
|
||||
property block
|
||||
|
||||
def initialize(&@block : HTTP::Server::Context -> _)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def add_filters
|
||||
|
|
|
@ -41,5 +41,4 @@ class Kemal::RouteHandler < HTTP::Handler
|
|||
node = radix_path method, path
|
||||
@tree.add node, route
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue