12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/pekky/server.rb', line 12
def self.call(env)
Pekky.build
path = env['PATH_INFO']
if path.match(/\.(\w+)$/)
file = File.join(Config[:output_dir], path)
type = Rack::Mime.mime_type(File.extname(path))
else
file = File.join(Config[:output_dir], path, "index.html")
type = "text/html"
end
if File.exists?(file)
output = File.open(file).read
[200, {"Content-Type" => type}, [output]]
else
[200, {"Content-Type" => "text/html"}, "Oh, file is not found; Pekky cries for you."]
end
end
|