Class: ActionDispatch::Static
- Inherits:
-
Object
- Object
- ActionDispatch::Static
- Defined in:
- lib/action_dispatch/middleware/static.rb
Overview
This middleware serves static files from disk, if available. If no file is found, it hands off to the main app.
In Rails apps, this middleware is configured to serve assets from the public/
directory.
Only GET and HEAD requests are served. POST and other HTTP methods are handed off to the main app.
Only files in the root directory are served; path traversal is denied.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, path, index: "index", headers: {}) ⇒ Static
constructor
A new instance of Static.
Constructor Details
#initialize(app, path, index: "index", headers: {}) ⇒ Static
Returns a new instance of Static.
17 18 19 20 |
# File 'lib/action_dispatch/middleware/static.rb', line 17 def initialize(app, path, index: "index", headers: {}) @app = app @file_handler = FileHandler.new(path, index: index, headers: headers) end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 |
# File 'lib/action_dispatch/middleware/static.rb', line 22 def call(env) @file_handler.attempt(env) || @app.call(env) end |