Skip to content

Instantly share code, notes, and snippets.

@pmkhoa
Created February 8, 2020 01:20
Show Gist options
  • Save pmkhoa/4ed29d298b6cc02aa725f6b35f201369 to your computer and use it in GitHub Desktop.
Save pmkhoa/4ed29d298b6cc02aa725f6b35f201369 to your computer and use it in GitHub Desktop.
CORS for Sinatra
before do
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Headers'] = 'accept, authorization, origin'
end
options '*' do
response.headers['Allow'] = 'HEAD,GET,PUT,DELETE,OPTIONS,POST'
response.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment