Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
set CORS headers (#99)
Browse files Browse the repository at this point in the history
* Update application.rb

* Update Gemfile

* Only allow zeus.ugent.be cors
  • Loading branch information
werthen authored and Procrat committed Jun 29, 2016
1 parent 54c9b47 commit 6a6ff2d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ gem 'jbuilder', '~> 1.2'
# Build google charts
gem 'google_visualr'

# CORS
gem 'rack-cors', :require => 'rack/cors'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ GEM
byebug (~> 4.0)
pry (~> 0.10)
rack (1.5.5)
rack-cors (0.4.0)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.8)
Expand Down Expand Up @@ -325,6 +326,7 @@ DEPENDENCIES
omniauth
omniauth-github
pry-byebug
rack-cors
rack-test
rails (~> 4.1)
rspec-rails
Expand Down
8 changes: 8 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class Application < Rails::Application
g.fixture_replacement :factory_girl, dir: 'spec/factories'
end

# CORS headers
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins /localhost(:\d+)?/, 'zeus.ugent.be'
resource '*', :headers => :any, :methods => [:get, :options]
end
end

# Backport from Rails 4.2: custom configurations
# Just remove this block when upgrading from 4.1.8 to 4.2
if Rails.version == '4.1.8'
Expand Down

0 comments on commit 6a6ff2d

Please sign in to comment.