Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rhildred/simplerailscorsexample

This is pretty much the least that I could have and send the Access-Control-Allow-Origin
https://github.com/rhildred/simplerailscorsexample

Last synced: 13 days ago
JSON representation

This is pretty much the least that I could have and send the Access-Control-Allow-Origin

Awesome Lists containing this project

README

        

Basic CORS
====

1. Did a `rails new`
1. Edited resulting app/controllers/application_controller.rb [per.](http://leopard.in.ua/2012/07/08/using-cors-with-rails/)
1. Added

before_filter :set_headers

private

def set_headers
if request.headers["HTTP_ORIGIN"]
# better way check origin
# if request.headers["HTTP_ORIGIN"] && /^https?:\/\/(.*)\.some\.site\.com$/i.match(request.headers["HTTP_ORIGIN"])
headers['Access-Control-Allow-Origin'] = request.headers["HTTP_ORIGIN"]
headers['Access-Control-Expose-Headers'] = 'ETag'
headers['Access-Control-Allow-Methods'] = 'GET, POST, PATCH, PUT, DELETE, OPTIONS, HEAD'
headers['Access-Control-Allow-Headers'] = '*,x-requested-with,Content-Type,If-Modified-Since,If-None-Match,Auth-User-Token'
headers['Access-Control-Max-Age'] = '86400'
headers['Access-Control-Allow-Credentials'] = 'true'
end
end

1. `rails generate controller welcome index`
1. changed config/routes.rb to uncomment root route