Project

hobby-cors

0.0
No release in over 3 years
Low commit activity in last 3 years
A Rack middleware for CORS, with permissive defaults.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 2
 Project Readme

Introduction

Hobby-CORS is a Rack middleware for CORS, with permissive defaults. It is available on RubyGems as hobby-cors.

By default, it responds with permissive headers to POST requests from any origin. You can use it with Hobby as follows:

require 'hobby'
require 'hobby/cors'

class App
  include Hobby
  use CORS

  post {
    'return some value'
  }
end

To restrict the origins for which CORS will be allowed, you can pass an origins Array:

require 'hobby'
require 'hobby/cors'

class App
  include Hobby

  def initialize cors_origins: nil
    if cors_headers
      use CORS, origins: cors_origins
    else
      use CORS
    end
  end

  post {
    'return some value'
  }
end

Development

To run the specs:

bundle exec rspec