Class: Crystal::StaticFiles

Inherits:
Object show all
Defined in:
lib/crystal/http/middleware/static_files.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, root) ⇒ StaticFiles

Returns a new instance of StaticFiles.



4
5
6
7
8
# File 'lib/crystal/http/middleware/static_files.rb', line 4

def initialize(app, root)
  @app = app
  @root = File.expand_path(root)
  @file_server = Rack::File.new(@root)
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/crystal/http/middleware/static_files.rb', line 10

def call(env)
  path = env["PATH_INFO"]

  if File.exist? "#{@root}#{path}"
    @file_server.call(env)
  else
    @app.call(env)
  end
end