Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
Created April 12, 2015 12:55
Show Gist options
  • Save oojikoo-gist/2eb19edcca33b00be8c2 to your computer and use it in GitHub Desktop.
Save oojikoo-gist/2eb19edcca33b00be8c2 to your computer and use it in GitHub Desktop.
rails: cors whitelist

Cross Origin Resource Sharing

Whitelist in Rails:

Gemfile

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

config/application.rb

module Sample
   class Application < Rails::Application
       config.middleware.use Rack::Cors do
           allow do
               origins 'someserver.example.com'
               resource %r{/users/\d+.json},
                   :headers => ['Origin', 'Accept', 'Content-Type'],
                   :methods => [:post, :get]
           end
       end
   end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment