Skip to content

Instantly share code, notes, and snippets.

@hendra
Created March 18, 2020 03:49
Show Gist options
  • Save hendra/7689eefa97911b0ac996c6f233327922 to your computer and use it in GitHub Desktop.
Save hendra/7689eefa97911b0ac996c6f233327922 to your computer and use it in GitHub Desktop.
rails cors
# Be sure to restart your server when you modify this file.
# Avoid CORS issues when API is called from the frontend app.
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
# Read more: https://github.com/cyu/rack-cors
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource(
'/api/*',
headers: %w(Authorization),
methods: :any,
expose: ["Authorization"],
max_age: 600
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment