Class: Decidim::Middleware::StaticDispatcher

Inherits:
ActionDispatch::Static
  • Object
show all
Defined in:
decidim-core/lib/decidim/middleware/static_dispatcher.rb

Overview

A middleware that handles static assets serving. This extends from ActionDispatch::Static and adds the ability to serve compressed images also when running under the puma server solely.

On production environments, the static files should be served directly from the HTTP server in front of the application. This mainly used for development and testing environments but also serves as a backup option to ensure these assets are transferred using proper compression.

Instance Method Summary collapse

Constructor Details

#initialize(app, path, index: "index", headers: {}) ⇒ StaticDispatcher

Initializes the Rack Middleware.

app - The Rack application path - The root path for the static files index - The index file route for folders headers - Additional response headers



20
21
22
23
24
25
26
27
28
# File 'decidim-core/lib/decidim/middleware/static_dispatcher.rb', line 20

def initialize(app, path, index: "index", headers: {})
  @app = app
  @file_handler = ActionDispatch::FileHandler.new(
    path,
    index:,
    headers:,
    compressible_content_types: %r{\A(?:(text|image)/|application/javascript)}
  )
end