I have searched all over StackOverflow and saw similar questions but have not found a working solution. Wondering if anyone has a working solution? I am developing a create react app on localhost:3000 and trying to access through my Apollo Client a URI on a different site (I am testing with https://developer.github.com/v4/explorer/).
I have added the fetchOptions mode of 'no-cors' to my new ApolloClient instance but I am still getting a CORS error in my console. My enitre index.js file is below:
import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloProvider } from 'react-apollo';
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-boost';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
const client = new ApolloClient({
link: new HttpLink({ uri: 'https://developer.github.com/v4/explorer/' }),
fetchOptions: {
mode: 'no-cors',
},
cache: new InMemoryCache()
});
const AppWithProvider = () => (
<ApolloProvider client={client}>
<App />
</ApolloProvider>
);
ReactDOM.render(<AppWithProvider />, document.getElementById('root'));
serviceWorker.unregister();
Error message in console: Access to fetch at 'https://developer.github.com/v4/explorer/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.