问题描述:

I am trying to use Rack-cors gem to enable cors. The issue is that for non-get requests the header is coming bur for GET requests the header is not present.

In application.rb

 config.middleware.insert_before ActionDispatch::Static, Rack::Cors do

allow do

origins '*.example.com'

resource '*', :headers => :any, :methods => [:get, :post, :options]

end

end

  • Searched rack:cors issue but not able to found any solution .

Any idea what is wrong here?

网友答案:

Its working for me. Having following configuration in application.rb

config.middleware.insert_before 0, "Rack::Cors" do
  allow do
    origins *Rails.application.secrets.cors_origins
    resource '/posts', headers: :any, methods: [:get, :post, :options]
    resource '/post', headers: :any, methods: [:post, :options]
  end
end
相关阅读:
Top