小编Dar*_*ier的帖子

Next JS 被 CORS 阻止:没有 HTTP 正常状态

我正在使用 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)

node.js cors apollo next.js apollo-client

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

apollo ×1

apollo-client ×1

cors ×1

next.js ×1

node.js ×1