【问题标题】:Failed to fetch获取失败
【发布时间】:2019-07-23 13:02:22
【问题描述】:

我正在尝试使用 next.js 构建应用程序,前端是 apollo 客户端,后端是 graphql-yoga 和 prisma,但我在将 apollo 客户端扩展到 chrome 时遇到问题,它无法获取我的日期。这就是它的外观。 Failed to fetch error picture。还有代码:

import withApollo from "next-with-apollo";
import ApolloClient from "apollo-boost";
import { endpoint } from "../config";

function createClient({ headers }) {
  return new ApolloClient({
    uri: process.env.NODE_ENV === "development" ? endpoint : endpoint,
    request: operation => {
      operation.setContext({
        fetchOptions: {
          credentials: "include",
          connectToDevTools: true
        },
        headers
      });
    }
  });
}

export default withApollo(createClient);

我知道这一定是我的愚蠢失误,但我找不到。感谢所有尝试帮助我的人。

【问题讨论】:

    标签: javascript reactjs next.js google-chrome-devtools react-apollo


    【解决方案1】:

    您是否尝试在服务器上启用 cors?

    import cors from 'cors'
    const app = express();
    app.use(cors('*'))
    

    https://www.prisma.io/blog/enabling-cors-for-express-graphql-apollo-server-1ef999bfb38d

    【讨论】:

      猜你喜欢
      • 2021-11-17
      • 2012-08-08
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 2021-07-09
      • 2019-11-19
      • 1970-01-01
      相关资源
      最近更新 更多