CORS Apollo React只有前端

问题描述 投票:1回答:1

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

cors apollo react-apollo
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' }));
© www.soinside.com 2019 - 2024. All rights reserved.