動作派遣靜態
如果可用,此中間件會從磁碟提供靜態檔案。如果找不到檔案,它會交給主應用程式。
在 Rails 應用程式中,此中間件會設定為提供來自 public/
目錄的資產。
只提供 GET 和 HEAD 要求。POST 和其他 HTTP 方法會交給主應用程式。
只提供根目錄中的檔案;拒絕路徑穿越。
方法
類別公開方法
new(app, path, index: "index", headers: {}) 連結
來源:顯示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/static.rb, line 19 def initialize(app, path, index: "index", headers: {}) @app = app @file_handler = FileHandler.new(path, index: index, headers: headers) end
執行個體公開方法
call(env) 連結
來源:顯示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/static.rb, line 24 def call(env) @file_handler.attempt(env) || @app.call(env) end