require 'rack/cors'
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins CORS_ORIGINS[Rails.env]
resource '*', :headers => :any, :methods => [:get, :post, :options, :put, :delete],credentials: true
end
end
字符串
我正在使用**gem 'rack-cors'**这在我的不同项目中工作得很好,但目前在ruby '2.7.6',rails '5.1.7'中我面临一些问题,我不确定这是因为ruby on rails的版本还是其他原因。
/config/initializers/cors.rb
正如gem 'rack-cors'中提到的,在上面的文件中编写的代码,也在config.ru中尝试过,后来在/config/application.rb中尝试过
我在打印一些信息,
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
puts "************cors************"
origins CORS_ORIGINS[Rails.env]
resource '*', :headers => :any, :methods => [:get, :post, :options, :put, :delete],credentials: true
end
end
型
在上述情况下也会打印此消息,但在服务器上部署时,这不起作用。
1条答案
按热度按时间cgyqldqp1#
我有一个几乎类似的环境,并有一个工作CORS管理.也许这有助于.我整理出起源fesert,然后把资源.
字符串