Class: Proscenium::Middleware::Vendor

Inherits:
Object
  • Object
show all
Defined in:
lib/proscenium/middleware/vendor.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Vendor

Returns a new instance of Vendor.



6
7
8
# File 'lib/proscenium/middleware/vendor.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/proscenium/middleware/vendor.rb', line 10

def call(env)
  request = ActionDispatch::Request.new(env)
  pathname = Pathname.new(request.path)

  return @app.call(env) unless pathname.fnmatch?(VENDOR_PATH_GLOB, File::FNM_EXTGLOB)

  request.path_info = request.path.delete_prefix('/vendor')

  ActionDispatch::FileHandler.new(
    Rails.root.join('vendor').to_s,
    headers: {
      'X-Proscenium-Middleware' => 'vendor',
      'Cache-Control' => "public, max-age=#{100.years}, immutable"
    }
  ).attempt(request.env) || @app.call(env)
end