Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/rhildred/simplerailscorsexample
- Owner: rhildred
- Created: 2015-01-22T03:21:48.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-29T22:20:31.000Z (almost 10 years ago)
- Last Synced: 2024-04-14T14:03:16.124Z (9 months ago)
- Language: Ruby
- Size: 156 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
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. Addedbefore_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