跳至內容 跳至搜尋

Action Dispatch Static

如果可用,這個中間件會提供硬碟上的靜態檔案。如果找不到任何檔案,它會移交給主應用程式。

Rails 應用程式中,這個中間件會設定為從 public/ 目錄提供資源。

僅會提供 GET 和 HEAD 請求。POST 與其他 HTTP 方法會移交給主應用程式。

僅會提供根目錄裡的檔案;路徑穿越是被禁止的。

方法
C
N

類別公開方法

new(app, path, index: "index", headers: {})

# File actionpack/lib/action_dispatch/middleware/static.rb, line 21
def initialize(app, path, index: "index", headers: {})
  @app = app
  @file_handler = FileHandler.new(path, index: index, headers: headers)
end

執行個體公開方法

call(env)

# File actionpack/lib/action_dispatch/middleware/static.rb, line 26
def call(env)
  @file_handler.attempt(env) || @app.call(env)
end