所以我graphql API是在https://gpbaculio-tributeapp.herokuapp.com/graphql我cnofigured上傳,標題是這樣的:即使使用「Access-Control-Allow-Origin」,服務器也會響應405錯誤:'*'?
const fetchQuery = (operation, variables) => {
return fetch('/graphql', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify({
query: operation.text,
variables,
}),
}).then(response => {
return response.json()
})
}
我從MDN
For requests without credentials, the server may specify "*" as a wildcard, thereby allowing any origin to access the resource.
,所以我試圖發佈在codepen的應用程式閱讀,而這是我的錯誤:
Failed to load https://gpbaculio-tributeapp.herokuapp.com/graphql : Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' https://s.codepen.io '
爲什麼它告訴我,它不通過「訪問控制允許來源」的消息頭,有什麼錯我的標題配置?
但即使我已經試過訪問控制允許來源:s.codepen.io仍然會返回錯誤? –
交叉原點的CORS解決方案需要服務器和客戶端合作配置解決方案。而'Access-Control-Allow-Origin'頭只是所有操作之一。更多信息,請訪問https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS – JiangangXiong