This repository was archived by the owner on Jul 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +82
-5
lines changed
Expand file tree Collapse file tree 7 files changed +82
-5
lines changed Original file line number Diff line number Diff line change 77 </ head >
88 < body class ="theme-minder ">
99 < div id ="root "> </ div >
10+ < script >
11+ window . APP_CONFIG = {
12+ BASE_API_URL : '${BASE_API_URL}' ,
13+ }
14+ </ script >
1015 < script type ="module " src ="/src/main.tsx "> </ script >
1116 </ body >
1217</ html >
Original file line number Diff line number Diff line change 1+ export interface AppConfig {
2+ BASE_API_URL ?: string
3+ }
4+
5+ declare global {
6+ interface Window {
7+ APP_CONFIG : AppConfig
8+ }
9+ }
10+
11+ export { }
Original file line number Diff line number Diff line change @@ -6,16 +6,17 @@ import {
66 v1GetWorkspaceMessagesQueryKey ,
77} from '@/api/generated/@tanstack/react-query.gen'
88import { invalidateQueries } from '@/lib/react-query-utils'
9+ import { getAppConfig } from '@/lib/utils'
910
10- const BASE_URL = import . meta . env . VITE_BASE_API_URL
11+ const baseApiUrl = getAppConfig ( ) . BASE_API_URL
1112
1213export function useSse ( ) {
1314 const location = useLocation ( )
1415 const queryClient = useQueryClient ( )
1516
1617 useEffect ( ( ) => {
1718 const eventSource = new EventSource (
18- `${ BASE_URL } /api/v1/alerts_notification`
19+ `${ baseApiUrl } /api/v1/alerts_notification`
1920 )
2021
2122 eventSource . onmessage = function ( event ) {
Original file line number Diff line number Diff line change 1+ import { getAppConfig } from '../utils'
2+ import { AppConfig } from '@/global'
3+
4+ describe ( 'getAppConfig' , ( ) => {
5+ const mockViteBaseApiUrl = 'https://api.mock.com'
6+
7+ it ( 'default base api url if ${BASE_API_URL}" not configured' , ( ) => {
8+ const mockAppConfig : AppConfig = {
9+ BASE_API_URL : '${BASE_API_URL}' ,
10+ }
11+
12+ Object . defineProperty ( window , 'APP_CONFIG' , {
13+ value : mockAppConfig ,
14+ writable : true ,
15+ } )
16+
17+ const expectedConfig : AppConfig = {
18+ ...mockAppConfig ,
19+ BASE_API_URL : 'https://mock.codegate.ai' ,
20+ }
21+
22+ expect ( getAppConfig ( ) ) . toEqual ( expectedConfig )
23+ } )
24+
25+ it ( 'replace base api url if ${BASE_API_URL}" is configured' , ( ) => {
26+ const mockAppConfig : AppConfig = {
27+ BASE_API_URL : mockViteBaseApiUrl ,
28+ }
29+
30+ Object . defineProperty ( window , 'APP_CONFIG' , {
31+ value : mockAppConfig ,
32+ writable : true ,
33+ } )
34+
35+ const expectedConfig : AppConfig = {
36+ ...mockAppConfig ,
37+ BASE_API_URL : mockViteBaseApiUrl ,
38+ }
39+
40+ expect ( getAppConfig ( ) ) . toEqual ( expectedConfig )
41+ } )
42+ } )
Original file line number Diff line number Diff line change 11import { format } from 'date-fns'
2+ import { AppConfig } from '@/global'
23
34const FILEPATH_REGEX = / (?: - - - F I L E P A T H | P a t h : | \/ \/ \s * f i l e p a t h : ) \s * ( [ ^ \s ] + ) / g
45const COMPARE_CODE_REGEX = / C o m p a r e t h i s s n i p p e t [ ^ : ] * : / g
@@ -70,3 +71,19 @@ export function sanitizeQuestionPrompt({
7071 return question
7172 }
7273}
74+
75+ export function getAppConfig ( ) : AppConfig {
76+ const baseApiUrl = window . APP_CONFIG ?. BASE_API_URL
77+
78+ if ( ! baseApiUrl || baseApiUrl === '${BASE_API_URL}' ) {
79+ return {
80+ ...window . APP_CONFIG ,
81+ BASE_API_URL : import . meta. env . VITE_BASE_API_URL ,
82+ }
83+ }
84+
85+ return {
86+ ...window . APP_CONFIG ,
87+ BASE_API_URL : baseApiUrl ,
88+ }
89+ }
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import './index.css'
44import './code.css'
55import '@stacklok/ui-kit/style'
66import App from './App.tsx'
7-
87import ErrorBoundary from './components/ErrorBoundary.tsx'
98import { Error } from './components/Error.tsx'
109import { DarkModeProvider , Toaster } from '@stacklok/ui-kit'
@@ -14,10 +13,11 @@ import { BrowserRouter } from 'react-router-dom'
1413import { UiKitClientSideRoutingProvider } from './lib/ui-kit-client-side-routing.tsx'
1514import { ConfirmProvider } from './context/confirm-context.tsx'
1615import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
16+ import { getAppConfig } from './lib/utils.ts'
1717
1818// Initialize the API client
1919client . setConfig ( {
20- baseUrl : import . meta . env . VITE_BASE_API_URL ,
20+ baseUrl : getAppConfig ( ) . BASE_API_URL ,
2121} )
2222
2323createRoot ( document . getElementById ( 'root' ) ! ) . render (
Original file line number Diff line number Diff line change 2929 " openapi-ts.config.ts" ,
3030 " tailwind.config.ts" ,
3131 " vitest.config.ts" ,
32- " vitest.setup.ts"
32+ " vitest.setup.ts" ,
33+ " ./global.d.ts"
3334 ],
3435 "exclude" : [" node_modules" ]
3536}
You can’t perform that action at this time.
0 commit comments