I have a pretty silly question. I have a graphQL API from not mine, online server. I have some problems with CORS(works fine when i do some magic in my browser). Every question like this was about server side, but here I can't do anything with server. So is there any possibility to get data by frontend without any issues? I use React Apollo stack.
Asked
Active
Viewed 547 times
1
-
1Yes, you can use a proxy. See the answer at https://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource/42744707#42744707 – sideshowbarker Apr 19 '17 at 11:09
1 Answers
0
I fix the cors problem adding this line "graphQLServer.use(cors())" to my graphql server:
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' }));

Yahima Duarte
- 59
- 1