From 733b4a8e5316aa770999fc7844d49074efd318d4 Mon Sep 17 00:00:00 2001 From: Ben Elferink Date: Wed, 20 Nov 2024 14:01:25 +0200 Subject: [PATCH] [GEN-1745]: fix API base URL for production events (attempt to fix SSE) (#1795) --- frontend/webapp/lib/gql/apollo-wrapper.tsx | 12 +++++----- frontend/webapp/utils/constants/urls.tsx | 26 ++++++++++------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/frontend/webapp/lib/gql/apollo-wrapper.tsx b/frontend/webapp/lib/gql/apollo-wrapper.tsx index d62aefb4b..59ec838b4 100644 --- a/frontend/webapp/lib/gql/apollo-wrapper.tsx +++ b/frontend/webapp/lib/gql/apollo-wrapper.tsx @@ -1,20 +1,18 @@ 'use client'; +import { API } from '@/utils'; +import { onError } from '@apollo/client/link/error'; import { ApolloLink, HttpLink } from '@apollo/client'; import { ApolloNextAppProvider, InMemoryCache, ApolloClient, SSRMultipartLink } from '@apollo/experimental-nextjs-app-support'; -import { onError } from '@apollo/client/link/error'; -import { API } from '@/utils'; function makeClient() { const httpLink = new HttpLink({ - uri: API.BASE_URL, + uri: API.GRAPHQL, }); const errorLink = onError(({ graphQLErrors, networkError }) => { - if (graphQLErrors) { - graphQLErrors.forEach(({ message, locations, path }) => console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`)); - } - if (networkError) console.log(`[Network error]: ${networkError}`); + if (graphQLErrors) graphQLErrors.forEach(({ message, locations, path }) => console.warn(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`)); + if (networkError) console.warn(`[Network error]: ${networkError}`); }); return new ApolloClient({ diff --git a/frontend/webapp/utils/constants/urls.tsx b/frontend/webapp/utils/constants/urls.tsx index 0e1312af4..c5912c989 100644 --- a/frontend/webapp/utils/constants/urls.tsx +++ b/frontend/webapp/utils/constants/urls.tsx @@ -1,21 +1,19 @@ 'use client'; -const ENV = process.env.NODE_ENV; -const IS_PRODUCTION = ENV === 'production'; +const IS_PROD = process.env.NODE_ENV === 'production'; -// Define base URLs depending on the environment and rendering context -const LOCAL_API_BASE = 'http://localhost:8085'; -//we use localhost:8085 as the base URL for server environment -const PRODUCTION_GQL_API_BASE = IS_PRODUCTION && typeof window !== 'undefined' ? `${window.location.origin}/graphql` : `${LOCAL_API_BASE}/graphql`; -const API_BASE_URL = IS_PRODUCTION ? PRODUCTION_GQL_API_BASE : `${LOCAL_API_BASE}/graphql`; +// set base URLs for all environments +const DEV_API_URL = 'http://localhost:8085'; +const PROD_API_URL = typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000'; -// Define endpoints based on the base URL +// construct final base URL based on environment +const API_BASE_URL = IS_PROD ? PROD_API_URL : DEV_API_URL; + +// add paths to base URL const API = { - BASE_URL: API_BASE_URL, - EVENTS: `${IS_PRODUCTION ? '/' : LOCAL_API_BASE}/api/events`, + GRAPHQL: `${API_BASE_URL}/graphql`, + EVENTS: `${API_BASE_URL}/api/events`, }; -// Centralize external links -export const DOCS_LINK = 'https://docs.odigos.io'; +const DOCS_LINK = 'https://docs.odigos.io'; -// Export modules -export { API }; +export { API, DOCS_LINK };