Project

corsair

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Corsair adds Access-Control-Allow-Origin to the response headers, even if your app raises an error.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.7
~> 10.0
 Project Readme

Corsair

A Rack middleware that adds the simple request CORS Access-Control-Allow-Origin header to your application, even if the app raised an exception.

Installation

Require Corsair in your application's Gemfile:

gem "corsair"

In order for Corsair to do its thing it needs to be at the top of the middleware stack. For Rails, this will work nicely in your application.rb:

config.middleware.insert_before 0, "Rack::Corsair"

Options

By default, Corsair will add Access-Control-Allow-Origin: * to all your response headers. You can currently control which domain gets added instead of *, and which resources get the header added. You pass those options in a block, like this:

config.middleware.insert_before 0, "Rack::Corsair" do |corsair|
  corsair.allow_origin "*"
  corsair.allow_resource :things
end

License

Licensed under the MIT license. See the separate MIT-LICENSE file.