Skip to content

Instantly share code, notes, and snippets.

@daneb
Last active July 17, 2016 13:20
Show Gist options
  • Save daneb/48d907d9d07776a7bb85b5f734a5ccb0 to your computer and use it in GitHub Desktop.
Save daneb/48d907d9d07776a7bb85b5f734a5ccb0 to your computer and use it in GitHub Desktop.
Rack::Cors Configuration Middleware
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
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
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