Created
May 28, 2014 17:38
-
-
Save coderberry/71849b6c2a63802cf16c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module LearnLti | |
| class ApplicationController < ActionController::Base | |
| before_action :set_default_headers | |
| before_filter :cors_preflight_check | |
| after_filter :cors_set_access_control_headers | |
| def set_default_headers | |
| response.headers['X-Frame-Options'] = 'ALLOWALL' | |
| end | |
| # For all responses in this controller, return the CORS access control headers. | |
| def cors_set_access_control_headers | |
| headers['Access-Control-Allow-Origin'] = '*' | |
| headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS' | |
| headers['Access-Control-Request-Method'] = '*' | |
| headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization' | |
| headers['Access-Control-Max-Age'] = "1728000" | |
| end | |
| # If this is a preflight OPTIONS request, then short-circuit the | |
| # request, return only the necessary headers and return an empty | |
| # text/plain. | |
| def cors_preflight_check | |
| if request.method == :options | |
| headers['Access-Control-Allow-Origin'] = '*' | |
| headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS' | |
| headers['Access-Control-Allow-Headers'] = '*' | |
| headers['Access-Control-Max-Age'] = '1728000' | |
| render :text => '', :content_type => 'text/plain' | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment