내 Node5S 프론트 엔드 애플리케이션의 현재 실행중인 Rails 5 API 전용 앱 (http://localhost:3000
)을 지금 사용하고 싶습니다. http://localhost:8888
에 있습니다. Rspec에 따라 수신자 요청을 필터링하는 rack-cors가 아닌 이유
/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
it "should reject a request from a non-whitelisted domain" do
get "/api/v1/bodies.json", nil, "HTTP_ORIGIN": "https://foreign.domain"
expect(response.status).to eql(406)
end
end
. 하지만 두 번째 코드는 응답 코드 200으로 실패합니다. 왜?
(나는 방법에 의해 406 응답 코드에 결혼 아니에요;. 단 하나의 요청을 나타냅니다 충족되지 않습니다) 값에 따라 승인 요청에서 서버를 방지 할 수 없습니다