Assign @mime_types
This commit is contained in:
parent
d89f3fd8b9
commit
d5382e158f
1 changed files with 5 additions and 8 deletions
|
@ -8,6 +8,7 @@ class Server::Dir
|
||||||
|
|
||||||
def initialize(root)
|
def initialize(root)
|
||||||
@root = File.realpath(root)
|
@root = File.realpath(root)
|
||||||
|
@mime_types = {".ttf" => "font/ttf"}.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
@ -23,10 +24,6 @@ class Server::Dir
|
||||||
[500, {"content-length" => body.bytesize, "content-type" => "text/plain"}, [body]]
|
[500, {"content-length" => body.bytesize, "content-type" => "text/plain"}, [body]]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
attr_reader :root
|
|
||||||
|
|
||||||
def finish(request)
|
def finish(request)
|
||||||
path = find_path(request)
|
path = find_path(request)
|
||||||
body = File.binread(path)
|
body = File.binread(path)
|
||||||
|
@ -39,12 +36,12 @@ class Server::Dir
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
attr_reader :root, :mime_types
|
||||||
|
|
||||||
def find_path(request)
|
def find_path(request)
|
||||||
path = File.join root, File.expand_path(request.path)
|
path = File.join root, File.expand_path(request.path)
|
||||||
File.directory?(path) ? File.join(path, "index.html") : path
|
File.directory?(path) ? File.join(path, "index.html") : path
|
||||||
end
|
end
|
||||||
|
|
||||||
def mime_types
|
|
||||||
{".ttf" => "font/ttf"}.freeze
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue