Skip to content

Commit

Permalink
[GEN-1745]: fix API base URL for production events (attempt to fix SS…
Browse files Browse the repository at this point in the history
…E) (#1795)
  • Loading branch information
BenElferink authored Nov 20, 2024
1 parent 67af0aa commit 733b4a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
12 changes: 5 additions & 7 deletions frontend/webapp/lib/gql/apollo-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
26 changes: 12 additions & 14 deletions frontend/webapp/utils/constants/urls.tsx
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 733b4a8

Please sign in to comment.