diff --git a/Gemfile b/Gemfile index 063058d..c54fc92 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem 'puma', '~> 3.0' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'active_model_serializers' +gem 'rack-cors', :require => 'rack/cors' group :development, :test do gem 'byebug', platform: :mri diff --git a/Gemfile.lock b/Gemfile.lock index 7c43110..60e6d57 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,6 +114,7 @@ GEM public_suffix (2.0.5) puma (3.6.2) rack (2.0.1) + rack-cors (0.4.0) rack-test (0.6.3) rack (>= 1.0) rails (5.0.1) @@ -209,6 +210,7 @@ DEPENDENCIES listen (~> 3.0.5) pg (~> 0.18) puma (~> 3.0) + rack-cors rails (~> 5.0.1) rspec-rails (~> 3.5) sass-rails (~> 5.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694..4ac8823 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,2 @@ -class ApplicationController < ActionController::Base - protect_from_forgery with: :exception +class ApplicationController < ActionController::API end diff --git a/config/application.rb b/config/application.rb index b6a6fb1..f9ab3f8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -21,5 +21,14 @@ class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. + config.api_only = true + + config.middleware.insert_before 0, Rack::Cors do + allow do + origins '*' + resource '*', headers: :any, methods: [:get, :post, :options] + end + end + end end