Sha256: 7bb51188f4968fe1cb63faeb6d19db5a3ee63c96bd66a810db2f892947ae3f06

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require 'rack/cors'

# use Rack::Cors, :debug => true, :logger => ::Logger.new(STDOUT) do
use Rack::Lint
use Rack::Cors do
  allow do
    origins 'localhost:3000',
            '127.0.0.1:3000',
            %r{http://192\.168\.0\.\d{1,3}(:\d+)?},
            'file://',
            %r{http://(.*?)\.example\.com},
            'custom-protocol://abcdefg'

    resource '/get-only', methods: :get
    resource '/', headers: :any, methods: :any
    resource '/options', methods: :options
    resource '/single_header', headers: 'x-domain-token'
    resource '/two_headers', headers: %w[x-domain-token x-requested-with]
    resource '/expose_single_header', expose: 'expose-test'
    resource '/expose_multiple_headers', expose: %w[expose-test-1 expose-test-2]
    resource '/conditional', methods: :get, if: proc { |env| !!env['HTTP_X_OK'] }
    resource '/vary_test', methods: :get, vary: %w[Origin Host]
    resource '/patch_test', methods: :patch
    resource '/wildcard/*', methods: :any
    # resource '/file/at/*',
    #     :methods => [:get, :post, :put, :delete],
    #     :headers => :any,
    #     :max_age => 0
  end

  allow do
    origins do |source, _env|
      source.end_with?('10.10.10.10:3000')
    end
    resource '/proc-origin'
  end

  allow do
    origins ->(source, _env) { source.end_with?('10.10.10.10:3000') }
    resource '/lambda-origin'
  end

  allow do
    origins '*'
    resource '/public'
    resource '/public/*'
    resource '/public_without_credentials', credentials: false
  end

  allow do
    origins 'mucho-grande.com'
    resource '/multi-allow-config', max_age: 600
  end

  allow do
    origins '*'
    resource '/multi-allow-config', max_age: 300, credentials: false
  end

  allow do
    origins ''
    resource '/blank-origin'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-cors-2.0.1 test/unit/test.ru
rack-cors-2.0.0 test/unit/test.ru
rack-cors-2.0.0.rc1 test/unit/test.ru