Class: AssetAccessControl::Middleware
- Inherits:
-
Object
- Object
- AssetAccessControl::Middleware
- Defined in:
- lib/asset_access_control/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.
6 7 8 9 |
# File 'lib/asset_access_control/middleware.rb', line 6 def initialize(app, origin) @app = app @origin = origin end |
Instance Method Details
#access_control_headers ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/asset_access_control/middleware.rb', line 11 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
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/asset_access_control/middleware.rb', line 20 def call(env) # intercept the "preflight" request if env["REQUEST_METHOD"] == "OPTIONS" return [200, access_control_headers, []] else code, headers, body = @app.call(env) set_headers! headers, body, env["PATH_INFO"] [code, headers, body] end end |