Ruby Grape Api extension with Cross-origin resource sharing
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib typo fix Sep 8, 2014
.gitignore
Gemfile init commit Sep 3, 2014
LICENSE Initial commit Sep 3, 2014
README.md readme update and endpoint logic included Sep 3, 2014
Rakefile init commit Sep 3, 2014
VERSION
grape-cors.gemspec init commit Sep 3, 2014

README.md

grape-cors

Ruby Grape Api extension with Cross-origin resource sharing

Example:

  class API < Grape::API

    get :info do
      #> some logic here
    end

  end

  Grape::CORS.apply!
  #> and ready to use!

In case if you need to use the 'options' call, you should use by hand the following method:

  • init_cors_headers! because the apply method will not override the options enpoints (safety reasons) And otherwise, that option call will lack the required headers

if you want change any of the cors object, you can do so in the following way:

  #> Defaults
  Grape::CORS::Config.headers  #> [ 'Content-Type' ]
  Grape::CORS::Config.origin   #> [ '*' ]
  Grape::CORS::Config.methods  #> [ 'HEAD', 'OPTIONS', 'GET', 'POST', 'PUT', 'DELETE' ]

  Grape::CORS::Config.acah     #> 'Access-Control-Allow-Headers'
  Grape::CORS::Config.acao     #> 'Access-Control-Allow-Origin'
  Grape::CORS::Config.acam     #> 'Access-Control-Allow-Methods'
  Grape::CORS::Config.origin.clear
  Grape::CORS::Config.origin.push(some_origin_site)

Happy coding! :)