forked from puppetlabs/puppet-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ru
60 lines (48 loc) · 1.45 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
49
50
51
52
53
54
55
56
57
58
59
60
require 'pathname'
module Rack
class DirectoryWithIndexes < Rack::Directory
def initialize(*args)
super
end
def list_path_2x(env, path, path_info, script_name)
stat = ::File.stat(path)
if stat.readable?
return @app.call(env) if stat.file?
if stat.directory?
index = Pathname.new(path) + 'index.html'
if index.readable?
env['PATH_INFO'] = env['PATH_INFO'].sub(/\/?$/, '/index.html')
return @app.call(env)
else
return list_directory(path_info, path, script_name)
end
end
else
raise Errno::ENOENT, 'No such file or directory'
end
rescue Errno::ENOENT, Errno::ELOOP
return entity_not_found(path_info)
end
def list_path
@stat = ::File.stat(@path)
if @stat.readable?
return @app.call(@env) if @stat.file?
if @stat.directory?
index = Pathname.new(@path) + 'index.html'
if index.readable?
@env['PATH_INFO'] = @env['PATH_INFO'].sub(/\/?$/, '/index.html')
return @app.call(@env)
else
return list_directory
end
end
else
raise Errno::ENOENT, 'No such file or directory'
end
rescue Errno::ENOENT, Errno::ELOOP
return entity_not_found
end
end
end
puts ">>> Serving at http://localhost:9292"
run Rack::DirectoryWithIndexes.new(Pathname.new(__FILE__).parent + 'output')