我正在尝试使用Ruby on rails在rails应用程序中使用Heroku部署的api时遇到此错误:
Failed to load https://**: my API link deployed on Heroku No
'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
答案 0 :(得分:1)
http://localhost:3000。您需要在heroku上部署的rails应用程序中进行设置。
将以下代码段添加到config/application.rb
文件中,然后重新部署到heroku
config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3000'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end