我正在使用 GraphQL 在两个域客户端和服务器之间进行通信。我已按照vercel 文档在我的 API 网站上启用了 CORS ,但它似乎引发了blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.错误。我在 GraphQL 中有这样的代码:
function createApolloClient() {
return new ApolloClient({
ssrMode: typeof window === "undefined",
link: new HttpLink({
uri: <link>,
credentials: "include",
fetchOptions: {
mode: "cors",
},
}),
}),
...
}
Run Code Online (Sandbox Code Playgroud)
在API网站中,该next.config.js文件有这样的内容:
module.exports = {
async headers() {
return [
{
// matching all API routes
source: "/api/:path*",
headers: …Run Code Online (Sandbox Code Playgroud)