Class: Simple::Httpd::App::FileServer
- Inherits:
-
Object
- Object
- Simple::Httpd::App::FileServer
- Defined in:
- lib/simple/httpd/app/file_server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, url_prefix:, root:) ⇒ FileServer
constructor
A simple file server middleware.
Constructor Details
#initialize(app, url_prefix:, root:) ⇒ FileServer
A simple file server middleware
3 4 5 6 7 |
# File 'lib/simple/httpd/app/file_server.rb', line 3 def initialize(app, url_prefix:, root:) @app = app @url_prefix = File.join("/", url_prefix, "/") @file_server = Rack::File.new(root) end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/simple/httpd/app/file_server.rb', line 9 def call(env) request_path = env["PATH_INFO"] if request_path.start_with?(@url_prefix) file_path = request_path[@url_prefix.length..-1] env["PATH_INFO"] = file_path @file_server.call(env) else @app.call(env) end end |