42 lines
978 B
Crystal
42 lines
978 B
Crystal
|
# Adds given HTTP::Handler+ to handlers.
|
||
|
def add_handler(handler)
|
||
|
Kemal.config.add_handler handler
|
||
|
end
|
||
|
|
||
|
# Uses Kemal::Middleware::HTTPBasicAuth to easily add HTTP Basic Auth support.
|
||
|
def basic_auth(username, password)
|
||
|
auth_handler = Kemal::Middleware::HTTPBasicAuth.new(username, password)
|
||
|
add_handler auth_handler
|
||
|
end
|
||
|
|
||
|
# Sets public folder from which the static assets will be served.
|
||
|
# By default this is `/public` not `src/public`.
|
||
|
def public_folder(path)
|
||
|
Kemal.config.public_folder = path
|
||
|
end
|
||
|
|
||
|
# Logs to output stream.
|
||
|
# development: STDOUT in
|
||
|
# production: kemal.log
|
||
|
def log(message)
|
||
|
Kemal.config.logger.write "#{message}\n"
|
||
|
end
|
||
|
|
||
|
# Enables / Disables logging
|
||
|
def logging(status)
|
||
|
Kemal.config.logging = status
|
||
|
end
|
||
|
|
||
|
def logger(logger)
|
||
|
Kemal.config.logger = logger
|
||
|
Kemal.config.add_handler logger
|
||
|
end
|
||
|
|
||
|
def serve_static(status)
|
||
|
Kemal.config.serve_static = status
|
||
|
end
|
||
|
|
||
|
def headers(env, additional_headers)
|
||
|
env.response.headers.merge!(additional_headers)
|
||
|
end
|