2017-04-19 91 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' })); 
相關問題