2016-07-17 11:43:13 +00:00
|
|
|
module Kemal
|
|
|
|
# Kemal::StaticFileHandler is used to serve static files(.js/.css/.png e.g).
|
|
|
|
# This handler is on by default and you can disable it like.
|
|
|
|
#
|
|
|
|
# serve_static false
|
|
|
|
#
|
|
|
|
class StaticFileHandler < HTTP::StaticFileHandler
|
|
|
|
def call(context)
|
|
|
|
return call_next(context) if context.request.path.not_nil! == "/"
|
|
|
|
super
|
|
|
|
end
|
2016-09-15 16:35:34 +00:00
|
|
|
|
2016-08-19 14:49:29 +00:00
|
|
|
def mime_type(path)
|
|
|
|
case File.extname(path)
|
|
|
|
when ".txt" then "text/plain"
|
|
|
|
when ".htm", ".html" then "text/html"
|
|
|
|
when ".css" then "text/css"
|
|
|
|
when ".js" then "application/javascript"
|
|
|
|
when ".png" then "image/png"
|
|
|
|
when ".jpg", ".jpeg" then "image/jpeg"
|
|
|
|
when ".gif" then "image/gif"
|
|
|
|
when ".svg" then "image/svg+xml"
|
|
|
|
else "application/octet-stream"
|
|
|
|
end
|
|
|
|
end
|
2015-12-10 19:15:28 +00:00
|
|
|
end
|
|
|
|
end
|