当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - Rack:cors gem not setting cors header for GET requests

问题描述:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: