Module: Sinatra::Cors

Defined in:
lib/sinatra/cors.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/sinatra/cors.rb', line 117

def self.registered(app)
  app.helpers Cors::Helpers

  app.set :allow_origin, ""
  app.set :allow_methods, ""
  app.set :allow_headers, ""
  app.disable :max_age
  app.disable :expose_headers
  app.disable :allow_credentials

  app.set(:is_cors_preflight) do |bool|
    condition { is_cors_request? && is_preflight_request? == bool }
  end

  app.options "*", is_cors_preflight: true do
    allow = allowed_methods

    pass if allow.size == 1

    response.headers["Allow"] = allow.join ","
  end

  app.after do
    cors
  end
end