ruby on rails - rack-cors multiple origins with different resources

I know this is a little old but for those finding this I am solving this differently with Rails 5.1.4 api only

-

Origins

ENV['CORS_ORIGINS'] = 'https://domain.first.com, http://another.origin.io'

Cors

Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins ENV['CORS_ORIGINS'].split(',').map { |origin| origin.strip }

    resource '*',
      headers: :any,
      methods: [:get, :post, :put, :patch, :delete, :options, :head]
  end
end

After checking and testing it turns out it is the right syntax. You can add as many blocks as you need:

allow do
    origins '[the domain]'
    resource '[the resource/directories]', headers: :any, methods: [:get, :post, :options, :put, :delete]
end