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