42 lines
952 B
JavaScript
42 lines
952 B
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import './styles/index.css';
|
|
import { AUTH_TOKEN } from './constants';
|
|
import App from './components/App';
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
import { setContext } from '@apollo/client/link/context';
|
|
import {
|
|
ApolloProvider,
|
|
ApolloClient,
|
|
createHttpLink,
|
|
InMemoryCache
|
|
} from '@apollo/client';
|
|
|
|
const httpLink = createHttpLink({
|
|
uri: 'http://localhost:4000/djhb58fytkh476dk45yh49'
|
|
});
|
|
|
|
const authLink = setContext((_, { headers }) => {
|
|
const token = localStorage.getItem(AUTH_TOKEN);
|
|
return {
|
|
headers: {
|
|
...headers,
|
|
authorization: token ? `Bearer ${token}` : ''
|
|
}
|
|
};
|
|
});
|
|
|
|
const client = new ApolloClient({
|
|
link: authLink.concat(httpLink),
|
|
cache: new InMemoryCache()
|
|
});
|
|
|
|
ReactDOM.render(
|
|
<BrowserRouter>
|
|
<ApolloProvider client={client}>
|
|
<App />
|
|
</ApolloProvider>
|
|
</BrowserRouter>,
|
|
document.getElementById('root')
|
|
);
|