Refactor cross-origin

- Drop cross_origin gem
- Add header to all responses

#18
This commit is contained in:
Hakan Ensari 2016-04-24 15:39:08 +01:00
parent ae0e9a009a
commit 1d059cd049
4 changed files with 8 additions and 6 deletions

View File

@ -9,7 +9,6 @@ gem 'newrelic_rpm'
gem 'rake'
gem 'sequel_pg'
gem 'sinatra-jsonp'
gem 'sinatra-cross_origin'
gem 'unicorn'
gem 'yajl-ruby'

View File

@ -41,7 +41,6 @@ GEM
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
sinatra-cross_origin (0.3.2)
sinatra-jsonp (0.4.4)
multi_json (~> 1.8)
sinatra (~> 1.0)
@ -65,7 +64,6 @@ DEPENDENCIES
rake
sequel_pg
shotgun
sinatra-cross_origin
sinatra-jsonp
unicorn
yajl-ruby

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'sinatra'
require 'sinatra/cross_origin'
require 'sinatra/jsonp'
require 'yajl'
require 'quote'
@ -44,6 +43,10 @@ helpers do
end
end
before do
headers 'Access-Control-Allow-Origin' => '*'
end
get '/' do
jsonp details: 'http://fixer.io', version: App.version
end

View File

@ -53,7 +53,9 @@ describe 'the API' do
end
it 'allows cross-origin requests' do
get '/', {}, 'HTTP_ORIGIN' => 'http://localhost'
assert_equal 'http://localhost', headers['Access-Control-Allow-Origin']
%w(/ /latest /2012-11-20).each do |path|
get path
assert_equal '*', headers['Access-Control-Allow-Origin']
end
end
end