Project

grape-cors

0.0
No commit activity in last 3 years
No release in over 3 years
Super easy way to extend Grape with CORS! Just call Grape::CORS.apply after the api classes and you ready to go!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 0
 Project Readme

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! :)