Tag: rack cors

Rails跨域ajax获取请求(CORS)

我正在尝试在我的rails应用程序中实现google places api。 这是我在尝试使用从ajax请求获取数据的函数时遇到的错误: XMLHttpRequest cannot load . Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:3000’ is therefore not allowed access. 我正在使用rack-cors gem,我已将此片段添加到我的config / application.rb文件中: config.middleware.insert_before 0, “Rack::Cors” do allow do origins ‘*’ resource ‘*’, :headers => :any, :methods => [:get, :post, :options] […]

Rspec表示,为什么机架式磁盘不能过滤传入的请求

我希望我的Rails 5 API专用应用程序,现在运行在http://localhost:3000 ,只接受来自我的NodeJS前端应用程序的请求,现在运行在http://localhost:8888 。 所以我像这样配置了/config/initializers/cors.rb : Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins “http://localhost:8888” resource “*”, headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head] end end 我写了这个测试: #/spec/request/cors_request_spec.rb RSpec.feature “CORS protection”, type: :request do it “should accept a request from a whitelisted domain” do get “/api/v1/bodies.json”, nil, “HTTP_ORIGIN”: “http://localhost:8888” expect(response.status).to eql(200) end […]