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")
|
||||
|
|
|
@ -109,13 +109,13 @@ describe "Kemal::RouteHandler" do
|
|||
end
|
||||
|
||||
# Removed until there is a way to test multiple middlewares
|
||||
#it "renders 404 on not found" do
|
||||
# it "renders 404 on not found" do
|
||||
# kemal = Kemal::RouteHandler.new
|
||||
# request = HTTP::Request.new("GET", "/?message=world")
|
||||
# io_with_context = create_request_and_return_io(kemal, request)
|
||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
# client_response.status_code.should eq 404
|
||||
#end
|
||||
# end
|
||||
|
||||
# it "renders 500 on exception" do
|
||||
# kemal = Kemal::RouteHandler.new
|
||||
|
@ -190,13 +190,13 @@ describe "Kemal::RouteHandler" do
|
|||
end
|
||||
|
||||
# Removed until there is a way to test multiple middlewares
|
||||
#it "can't process HTTP HEAD requests for undefined GET routes" do
|
||||
# it "can't process HTTP HEAD requests for undefined GET routes" do
|
||||
# kemal = Kemal::RouteHandler.new
|
||||
# request = HTTP::Request.new("HEAD", "/")
|
||||
# io_with_context = create_request_and_return_io(kemal, request)
|
||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||
# client_response.status_code.should eq(404)
|
||||
#end
|
||||
# end
|
||||
|
||||
it "redirects user to provided url" do
|
||||
kemal = Kemal::RouteHandler.new
|
||||
|
|
|
@ -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)
|
||||
|
@ -31,6 +30,7 @@ at_exit do
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
require "colorize"
|
||||
require "http"
|
||||
|
||||
class Kemal::CommonLogHandler < Kemal::BaseLogHandler
|
||||
# INSTANCE = new
|
||||
class Kemal::CommonLogHandler < Kemal::BaseLogHandler
|
||||
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
|
||||
|
|
|
@ -40,11 +40,10 @@ end
|
|||
# Enables / Disables logging
|
||||
macro logging(status)
|
||||
Kemal.config.logging = {{status}}
|
||||
end
|
||||
end
|
||||
|
||||
macro logger(logger)
|
||||
|
||||
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
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
class Kemal::NullLogHandler < Kemal::BaseLogHandler
|
||||
class Kemal::NullLogHandler < Kemal::BaseLogHandler
|
||||
end
|
||||
|
|
|
@ -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