Class: FontAssets::Middleware
- Inherits:
-
Object
- Object
- FontAssets::Middleware
- Defined in:
- lib/font_assets/middleware.rb
Instance Method Summary collapse
- #access_control_headers ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, origin) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, origin) ⇒ Middleware
Returns a new instance of Middleware.
4 5 6 7 |
# File 'lib/font_assets/middleware.rb', line 4 def initialize(app, origin) @app = app @origin = origin end |
Instance Method Details
#access_control_headers ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/font_assets/middleware.rb', line 9 def access_control_headers { "Access-Control-Allow-Origin" => @origin, "Access-Control-Allow-Methods" => "GET", "Access-Control-Allow-Headers" => "x-requested-with", "Access-Control-Max-Age" => "3628800" } end |
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/font_assets/middleware.rb', line 18 def call(env) # intercept the "preflight" request if env["REQUEST_METHOD"] == "OPTIONS" return [200, access_control_headers, []] else code, headers, body = @app.call(env) headers.merge!(access_control_headers) if font_asset?(env["PATH_INFO"]) [code, headers, body] end end |