class Onsi::Middleware::CORSHeaders

Auto-Add CORS headers to all requests.

@example Setup The middleware

# in config/application.rb
module CoolApp
  class Application < Rails::Application
    config.middleware.use(Onsi::Middleware::CORSHeaders)
  end
end

Public Class Methods

new(app) click to toggle source

@private

Create a new instance of the middleware.

@param app [] Rack App

# File lib/onsi/middleware/cors_headers.rb, line 22
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source

@private

Called by the Middleware stack.

# File lib/onsi/middleware/cors_headers.rb, line 30
def call(env)
  status, headers, body = @app.call(env)

  cors_headers = Onsi::CORSHeaders.generate(env)

  [
    status,
    cors_headers.merge(headers),
    body
  ]
end