CORS Apollo React只有前端

时间:2017-04-19 08:21:15

标签: cors apollo react-apollo

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

1 个答案:

答案 0 :(得分: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' }));