Class: FileServer

Inherits:
Object
  • Object
show all
Defined in:
lib/railz_lite/controllers/static.rb

Constant Summary collapse

MIME_TYPES =
{
  '.txt' => 'text/plain',
  '.jpg' => 'image/jpeg',
  '.zip' => 'application/zip',
  '.css' => 'text/css',
  '.js' => 'text/javascript'
}

Instance Method Summary collapse

Instance Method Details

#call(env, asset_dir) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/railz_lite/controllers/static.rb', line 44

def call(env, asset_dir)
  res = Rack::Response.new
  file_name = requested_file_name(env, asset_dir)

  if File.exist?(file_name)
    serve_file(file_name, res)
  else
    res.status = 404
    res.write('File not found')
  end
  [res.status, res.headers, res.body]
end