Class: Actn::Api::Mw::Cors

Inherits:
Object
  • Object
show all
Includes:
Goliath::Rack::AsyncMiddleware
Defined in:
lib/actn/api/mw/cors.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Cors

Returns a new instance of Cors.



16
17
18
# File 'lib/actn/api/mw/cors.rb', line 16

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/actn/api/mw/cors.rb', line 20

def call(env)
  if env['REQUEST_METHOD'] == 'OPTIONS'
    [200, cors_headers(env,false), []]
  else
    super(env)
  end
end

#post_process(env, status, headers, body) ⇒ Object



28
29
30
31
# File 'lib/actn/api/mw/cors.rb', line 28

def post_process(env, status, headers, body)
  headers = cors_headers(env).merge(headers)
  [status, headers, body]
end