1

我有一个非常愚蠢的问题。我有一个不是我的在线服务器的 graphQL API。我在使用 CORS 时遇到了一些问题(当我在浏览器中使用魔法时效果很好)。像这样的每个问题都是关于服务器端的,但在这里我不能对服务器做任何事情。那么有没有可能通过前端获取数据而没有任何问题?我使用 React Apollo 堆栈。

4

1 回答 1

0

我修复了将这一行“graphQLServer.use(cors())”添加到我的 graphql 服务器的 cors 问题:

import cors from 'cors';

const graphQLServer = express();
graphQLServer.use(cors()); // with this line the cors problem is solved
...
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
于 2018-01-25T23:36:57.680 回答