Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CORS config #4

Merged
merged 1 commit into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'rack-cors', '~> 0.4.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ GEM
procto (0.0.3)
puma (3.6.0)
rack (2.0.1)
rack-cors (0.4.0)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.0.1)
Expand Down Expand Up @@ -178,6 +179,7 @@ DEPENDENCIES
byebug
listen (~> 3.0.5)
puma (~> 3.0)
rack-cors (~> 0.4.0)
rails (~> 5.0.0, >= 5.0.0.1)
rails_best_practices (~> 1.16.0)
reek (~> 3.4.0)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
3. `bundle install`
4. `rake db:create`
5. `rake db:migrate`
6. `rails s`
6. [Optional] Set your [frontend URL](https://github.com/cyu/rack-cors#origin) in `config/initializers/rack_cors.rb`
7. `rails s`
10 changes: 10 additions & 0 deletions config/initializers/rack_cors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module App
class Application < Rails::Application
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [:get, :post, :options, :put, :delete]
end
end
end
end