Skip to content

Instantly share code, notes, and snippets.

@onlyoneaman
Last active June 2, 2020 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlyoneaman/144a96058446d3ad85aa51a284635834 to your computer and use it in GitHub Desktop.
Save onlyoneaman/144a96058446d3ad85aa51a284635834 to your computer and use it in GitHub Desktop.
Handling CORS in Rails app
module Userapi
class Application < Rails::Application
#...
#Rails 3/4
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
#Rails 5/6
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment