Configure rack cors

This commit is contained in:
Hakan Ensari 2016-06-08 14:49:43 +01:00
parent d063f1ab24
commit 2bb4aeb497
2 changed files with 11 additions and 2 deletions

View File

@ -13,6 +13,13 @@ configure :production do
require 'newrelic_rpm'
end
use Rack::Cors do |config|
config.allow do
origins '*'
resource '*', headers: :any, methods: :get
end
end
helpers do
def quote
@quote ||= Quote.new(params).attributes.tap do |data|

View File

@ -53,15 +53,17 @@ describe 'the API' do
%w(/ /latest /2012-11-20).each do |path|
header 'Origin', '*'
get path
refute_empty headers['Access-Control-Allow-Methods']
assert headers.key?('Access-Control-Allow-Methods')
end
end
it 'responds to preflight requests' do
%w(/ /latest /2012-11-20).each do |path|
header 'Origin', '*'
header 'Access-Control-Request-Method', 'GET'
header 'Access-Control-Request-Headers', 'Content-Type'
options path
refute_empty headers['Access-Control-Allow-Methods']
assert headers.key?('Access-Control-Allow-Methods')
end
end
end