19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/vivlio_pack/viewer.rb', line 19
def call(env)
case path = env['REQUEST_PATH']
when '/'
content = File.read(VIEWER_PATH + '/index.html')
[200, { 'Content-Type': 'text/html' }, [content]]
when /^\/contents/
if path == '/contents'
content_path = 'contents/index.html'
else
content_path = path.slice(1..)
end
if File.exist?(content_path)
content = File.read(content_path)
ext = File.extname(path)
ctype = CONTENT_TYPES[ext]
[200, { 'Content-Type': ctype }, [content]]
else
[404, {}, []]
end
else
if File.exist?(VIEWER_PATH + path)
content = File.read(VIEWER_PATH + path)
ext = File.extname(path)
ctype = CONTENT_TYPES[ext]
[200, { 'Content-Type': ctype }, [content]]
else
[404, {}, []]
end
end
end
|