diff --git a/frontend/src/client.tsx b/frontend/src/client.tsx new file mode 100644 index 00000000..5ec892d0 --- /dev/null +++ b/frontend/src/client.tsx @@ -0,0 +1,18 @@ +import {ApolloClient, InMemoryCache} from "@apollo/client"; + +export let API_URL = "/query"; + +if (process.env.REACT_APP_API_URL) { + API_URL = process.env.REACT_APP_API_URL + "/query"; +} else if (process.env.NODE_ENV !== 'production') { + // For dev, maybe add another condition for tests + API_URL = "http://localhost:8080/query"; + +} + +console.log('API_URL: ' + API_URL); + +export const client = new ApolloClient({ + uri: API_URL, + cache: new InMemoryCache(), +}); diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index 06b8a803..b729512a 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -3,34 +3,18 @@ import ReactDOM from 'react-dom/client'; import './index.css'; import App from './App'; import reportWebVitals from './reportWebVitals'; -import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client'; +import {ApolloProvider} from '@apollo/client'; import '@fontsource/roboto/300.css'; import '@fontsource/roboto/400.css'; import '@fontsource/roboto/500.css'; import '@fontsource/roboto/700.css'; +import {client} from "./client"; // If you want to start measuring performance in your app, pass a function // to log results (for example: reportWebVitals(console.log)) // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals reportWebVitals(); -// Default for production, use the same server as the frontend -let API_URL = "/query"; - -if (process.env.REACT_APP_API_URL) { - API_URL = process.env.REACT_APP_API_URL + "/query"; -} else if (process.env.NODE_ENV !== 'production') { - // For dev, maybe add another condition for tests - API_URL = "http://localhost:8080/query"; -} - -console.log('API_URL: ' + API_URL); - -const client = new ApolloClient({ - uri: API_URL, - cache: new InMemoryCache(), -}); - // Supported in React 18+ const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement