Last active
July 17, 2016 13:20
-
-
Save daneb/48d907d9d07776a7bb85b5f734a5ccb0 to your computer and use it in GitHub Desktop.
Rack::Cors Configuration Middleware
This file contains 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
require 'rack' | |
require './cors_wired' | |
app = Rack::Builder.new do | |
use CorsWired.new | |
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] } | |
end | |
run app |
This file contains 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
require 'byebug' | |
require 'rack/cors' | |
require 'rack/builder' | |
# shrimp.rb | |
class CorsWired | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
use Rack::Cors do | |
allow do | |
origins '*' | |
resource '*', :headers => :any, :methods => [:get, :post, :put, :options, :delete], :credentials => false | |
end | |
end | |
@app.call(env) | |
end | |
end |
This file contains 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
require 'byebug' | |
require 'rack/cors' | |
# shrimp.rb | |
class CorsWired | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
cors = Rack::Cors.new(@app, {}) do | |
allow do | |
origins '*' | |
resource '*', :headers => :any, :methods => [:get, :post, :put, :options, :delete], :credentials => false | |
end | |
end | |
cors.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment