standardize http::handlers into reusable rack like middleware
Crack provides a set of common HTTP::Handlers
that are similar to Rack Middleware.
Each handler provides changes needed to the HTTP:
and the ability to configure:Context
the handler using a block that is yields to self for setting any properties.
Add this to your application’s shard.yml
:
dependencies:
crack:
github: kemalyst/crack
Add the handler to your HTTP::Server implementation:
require "crack"
require "http/server"
Crack::Handler::Logger.instance.config do |config|
config.logger = Logger.new(STDOUT)
end
Crack::Handler::Static.instance.config do |config|
config.public_folder = "./public"
config.default_file = "index.html"
end
HTTP::Server.new("127.0.0.1", 8080, [
Crack::Handler::Error.instance,
Crack::Handler::Logger.instance,
Crack::Handler::Static.instance,
]).listen
You can add these to Kemal
or any other framework that support HTTP::Handlers
in their stack.
If you want to add a handler to this library, please follow the pattern provided:
self.instance
method to instantiateself.config()
and config()
method that yields self to a block to set any properties neededproperty logger : Logger
that can be configured in the config methods. This should use the Logger
base from the stdlibHTTP:
:Context
, do so at the top of the handler so its clear what additions are being made