Skip to content

Instantly share code, notes, and snippets.

@joshwlewis
Last active August 29, 2015 13:56
Show Gist options
  • Save joshwlewis/9336402 to your computer and use it in GitHub Desktop.
Save joshwlewis/9336402 to your computer and use it in GitHub Desktop.
Rack::Cors doesn't insert headers when Rails app errors out. Fix it by inserting Rack::Cors at the top of your middleware stack.
config.middleware.insert 0, Rack::Cors do
allow do
origins(/^https:\/\/app.client.com$/)
resource '*',
headers: :any,
methods: [:get, :put, :post, :delete]
end
end
@joshwlewis
Copy link
Author

May solve your issues that look like this:

XMLHttpRequest cannot load https://api.server.com/. Origin https://app.client.com/ is not allowed by Access-Control-Allow-Origin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment