Rack:cors gem 不为 GET 请求设置 cors 标头



我正在尝试使用 Rack-cors gem 来启用 cors。问题是对于非 get 请求,标头即将出现在 GET 请求中,标头不存在。

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
  • 搜索机架:cors问题,但找不到任何解决方案。

知道这里出了什么问题吗?

它对我有用。在应用程序.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

最新更新