Class: Recipes::RackCors

Inherits:
Rails::AppBuilder
  • Object
show all
Defined in:
lib/potassium/recipes/rack_cors.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
# 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

#installObject



2
3
4
# File 'lib/potassium/recipes/rack_cors.rb', line 2

def install
  create
end

#rack_cors_configObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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