From f54808a200b84e4486b8f4d80af1804af54af957 Mon Sep 17 00:00:00 2001 From: Giuseppe Scuglia Date: Wed, 5 Mar 2025 15:19:19 +0100 Subject: [PATCH] refactor: dashboard api base url env --- index.html | 2 +- src/global.d.ts | 2 +- src/hooks/useSse.ts | 2 +- src/lib/__tests__/utils.test.ts | 12 ++++++------ src/lib/utils.ts | 8 ++++---- src/main.tsx | 2 +- src/vite-env.d.ts | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index bbd9fe72..89a4095c 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@
diff --git a/src/global.d.ts b/src/global.d.ts index 1f08e129..152a2b13 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,5 +1,5 @@ export interface AppConfig { - BASE_API_URL?: string + DASHBOARD_API_BASE_URL?: string } declare global { diff --git a/src/hooks/useSse.ts b/src/hooks/useSse.ts index 6c8a2207..50d3e438 100644 --- a/src/hooks/useSse.ts +++ b/src/hooks/useSse.ts @@ -8,7 +8,7 @@ import { import { invalidateQueries } from '@/lib/react-query-utils' import { getAppConfig } from '@/lib/utils' -const baseApiUrl = getAppConfig().BASE_API_URL +const baseApiUrl = getAppConfig().DASHBOARD_API_BASE_URL export function useSse() { const location = useLocation() diff --git a/src/lib/__tests__/utils.test.ts b/src/lib/__tests__/utils.test.ts index df94fd31..f1dbde59 100644 --- a/src/lib/__tests__/utils.test.ts +++ b/src/lib/__tests__/utils.test.ts @@ -4,9 +4,9 @@ import { AppConfig } from '@/global' describe('getAppConfig', () => { const mockViteBaseApiUrl = 'https://api.mock.com' - it('default base api url if ${BASE_API_URL}" not configured', () => { + it('default base api url if ${DASHBOARD_API_BASE_URL}" not configured', () => { const mockAppConfig: AppConfig = { - BASE_API_URL: '${BASE_API_URL}', + DASHBOARD_API_BASE_URL: '${DASHBOARD_API_BASE_URL}', } Object.defineProperty(window, 'APP_CONFIG', { @@ -16,15 +16,15 @@ describe('getAppConfig', () => { const expectedConfig: AppConfig = { ...mockAppConfig, - BASE_API_URL: 'https://mock.codegate.ai', + DASHBOARD_API_BASE_URL: 'https://mock.codegate.ai', } expect(getAppConfig()).toEqual(expectedConfig) }) - it('replace base api url if ${BASE_API_URL}" is configured', () => { + it('replace base api url if ${DASHBOARD_API_BASE_URL}" is configured', () => { const mockAppConfig: AppConfig = { - BASE_API_URL: mockViteBaseApiUrl, + DASHBOARD_API_BASE_URL: mockViteBaseApiUrl, } Object.defineProperty(window, 'APP_CONFIG', { @@ -34,7 +34,7 @@ describe('getAppConfig', () => { const expectedConfig: AppConfig = { ...mockAppConfig, - BASE_API_URL: mockViteBaseApiUrl, + DASHBOARD_API_BASE_URL: mockViteBaseApiUrl, } expect(getAppConfig()).toEqual(expectedConfig) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 2549a747..9cea1e5e 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -73,17 +73,17 @@ export function sanitizeQuestionPrompt({ } export function getAppConfig(): AppConfig { - const baseApiUrl = window.APP_CONFIG?.BASE_API_URL + const baseApiUrl = window.APP_CONFIG?.DASHBOARD_API_BASE_URL - if (!baseApiUrl || baseApiUrl === '${BASE_API_URL}') { + if (!baseApiUrl || baseApiUrl === '${DASHBOARD_API_BASE_URL}') { return { ...window.APP_CONFIG, - BASE_API_URL: import.meta.env.VITE_BASE_API_URL, + DASHBOARD_API_BASE_URL: import.meta.env.VITE_BASE_API_URL, } } return { ...window.APP_CONFIG, - BASE_API_URL: baseApiUrl, + DASHBOARD_API_BASE_URL: baseApiUrl, } } diff --git a/src/main.tsx b/src/main.tsx index 2dc9b587..c2ed7464 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -17,7 +17,7 @@ import { getAppConfig } from './lib/utils.ts' // Initialize the API client client.setConfig({ - baseUrl: getAppConfig().BASE_API_URL, + baseUrl: getAppConfig().DASHBOARD_API_BASE_URL, }) createRoot(document.getElementById('root')!).render( diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index e8dd3c9e..c997c680 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,5 +1,5 @@ /// interface ImportBaseApiEnv { - readonly BASE_API_URL: string + readonly DASHBOARD_API_BASE_URL: string readonly VITE_BASE_API_URL: string }