5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/raps/server.rb', line 5
def self.call(env)
root = Rails.root.join('public')
path = Rack::Utils.unescape(env['PATH_INFO'])
file = root.to_s + path
status = 404
= { 'Content-Type' => 'text/plain' }
content = nil
if File.exist?(file)
status = 200
mime = MimeMagic.by_path(file)
= { 'Content-Type' => mime ? mime.type : 'application/octet-stream' }
content = mime && mime.mediatype == 'text' ? File.read(file) : File.binread(file)
else
content = "file not found #{file}"
end
[ status, , [content] ]
end
|