Class: Upfluence::HTTP::Middleware::CORS

Inherits:
Object
  • Object
show all
Defined in:
lib/upfluence/http/middleware/cors.rb

Constant Summary collapse

HEADERS =
{
  'Access-Control-Allow-Origin' => '*',
  'Access-Control-Allow-Headers' => 'Authorization, Content-Type, Scope, X-Upfluence-Plugin-Version',
  'Access-Control-Allow-Methods' => 'GET, POST, PUT, OPTIONS, DELETE'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, headers = nil) ⇒ CORS

Returns a new instance of CORS.



11
12
13
14
# File 'lib/upfluence/http/middleware/cors.rb', line 11

def initialize(app, headers = nil)
  @app = app
  @headers = headers || HEADERS
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
# File 'lib/upfluence/http/middleware/cors.rb', line 16

def call(env)
  status, headers, body = options?(env) ? default_response : @app.call(env)
  [status, merge_headers(headers), body]
end