Skip to content

Instantly share code, notes, and snippets.

@alex-hall
Last active July 19, 2017 14:02
Show Gist options
  • Save alex-hall/3114a9b7a005905338064e8a01c0b01c to your computer and use it in GitHub Desktop.
Save alex-hall/3114a9b7a005905338064e8a01c0b01c to your computer and use it in GitHub Desktop.
Configure Sinatra for CORS (Whitelist from any domain, don't actually do this in production)
require 'sinatra'
set :server, 'webrick'
before do
response.headers['Access-Control-Allow-Origin'] = '*'
end
options '*' do
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, PATCH, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'content-type,x-csrf-token,x-requested-with'
200
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment