Class: Hyperdrive::Middleware::CORS

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

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ CORS

Returns a new instance of CORS.



6
7
8
9
# File 'lib/hyperdrive/middleware/cors.rb', line 6

def initialize(app, options = {})
  @app = app
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/hyperdrive/middleware/cors.rb', line 11

def call(env)
  status, headers, body = @app.call(env)
  allowed_methods = '*'
  unless env['hyperdrive.resource'].nil?
    allowed_methods = env['hyperdrive.resource'].allowed_methods
  end
  cors = cors_headers(allowed_methods)
  headers.merge!(cors)
  [status, headers, body]
end