-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconfig.ru
More file actions
55 lines (41 loc) · 1.51 KB
/
config.ru
File metadata and controls
55 lines (41 loc) · 1.51 KB
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
# frozen_string_literal: true
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)
raise Errno::ENOENT, 'No such file or directory' unless stat.readable?
return @app.call(env) if stat.file?
if stat.directory?
index = Pathname.new(path) + 'index.html'
return list_directory(path_info, path, script_name) unless index.readable?
env['PATH_INFO'] = env['PATH_INFO'].sub(%r{/?$}, '/index.html')
@app.call(env)
end
rescue Errno::ENOENT, Errno::ELOOP
entity_not_found(path_info)
end
def list_path(env = @env, path = @path, path_info = @path_info, script_name = @script_name)
@env = env
@path = path
@path_info = path_info
@script_name = script_name
@stat = ::File.stat(@path)
raise Errno::ENOENT, 'No such file or directory' unless @stat.readable?
return @app.call(@env) if @stat.file?
if @stat.directory?
index = Pathname.new(@path) + 'index.html'
return list_directory(@path_info, @path, @script_name) unless index.readable?
@env['PATH_INFO'] = @env['PATH_INFO'].sub(%r{/?$}, '/index.html')
@app.call(@env)
end
rescue Errno::ENOENT, Errno::ELOOP
entity_not_found(@path_info)
end
end
end
puts '>>> Serving at http://localhost:9292'
run Rack::DirectoryWithIndexes.new(Pathname.new(__FILE__).parent + 'output')