Class: Crystal::StaticFiles
- Defined in:
- lib/crystal/http/middleware/static_files.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, root) ⇒ StaticFiles
constructor
A new instance of StaticFiles.
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.(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 |