class Recipes::RackCors

Public Instance Methods

create() click to toggle source
# File lib/potassium/recipes/rack_cors.rb, line 6
def create
  gather_gem('rack-cors', '~> 1.1')
  recipe = self
  after(:gem_install) do
    application recipe.rack_cors_config
  end
end
install() click to toggle source
# File lib/potassium/recipes/rack_cors.rb, line 2
def install
  create
end
rack_cors_config() click to toggle source
# File lib/potassium/recipes/rack_cors.rb, line 14
  def rack_cors_config
    <<~RUBY
      config.middleware.insert_before 0, Rack::Cors do
        allow do
          origins '*'
          resource '/public/*', headers: :any, methods: :get
          resource '/api/*',
            headers: :any,
            expose: ['X-Page', 'X-PageTotal'],
            methods: [:get, :post, :patch, :put, :delete, :options]
        end
      end

    RUBY
  end