2017-04-19 53 views
1

我有一个非常愚蠢的问题。我有一个不是我的在线服务器的graphQL API。我有一些与CORS有关的问题(当我在浏览器中做一些魔术时,工作正常)。像这样的每个问题都是关于服务器端的,但在这里我无法对服务器做任何事情。那么有没有可能通过前端获取数据而没有任何问题?我使用React Apollo堆栈。CORS阿波罗只反应前端

+1

是的,你可以使用代理。请参阅https://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource/42744707#42744707上的答案 – sideshowbarker

回答

1

我解决这个问题CORS加入这一行 “graphQLServer.use(CORS())” 我graphql服务器:

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' })); 
相关问题