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 7
7
</ head >
8
8
< body class ="theme-minder ">
9
9
< div id ="root "> </ div >
10
+ < script >
11
+ window . APP_CONFIG = {
12
+ BASE_API_URL : '${BASE_API_URL}' ,
13
+ }
14
+ </ script >
10
15
< script type ="module " src ="/src/main.tsx "> </ script >
11
16
</ body >
12
17
</ 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 {
6
6
v1GetWorkspaceMessagesQueryKey ,
7
7
} from '@/api/generated/@tanstack/react-query.gen'
8
8
import { invalidateQueries } from '@/lib/react-query-utils'
9
+ import { getAppConfig } from '@/lib/utils'
9
10
10
- const BASE_URL = import . meta . env . VITE_BASE_API_URL
11
+ const baseApiUrl = getAppConfig ( ) . BASE_API_URL
11
12
12
13
export function useSse ( ) {
13
14
const location = useLocation ( )
14
15
const queryClient = useQueryClient ( )
15
16
16
17
useEffect ( ( ) => {
17
18
const eventSource = new EventSource (
18
- `${ BASE_URL } /api/v1/alerts_notification`
19
+ `${ baseApiUrl } /api/v1/alerts_notification`
19
20
)
20
21
21
22
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 1
1
import { format } from 'date-fns'
2
+ import { AppConfig } from '@/global'
2
3
3
4
const 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
4
5
const 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({
70
71
return question
71
72
}
72
73
}
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'
4
4
import './code.css'
5
5
import '@stacklok/ui-kit/style'
6
6
import App from './App.tsx'
7
-
8
7
import ErrorBoundary from './components/ErrorBoundary.tsx'
9
8
import { Error } from './components/Error.tsx'
10
9
import { DarkModeProvider , Toaster } from '@stacklok/ui-kit'
@@ -14,10 +13,11 @@ import { BrowserRouter } from 'react-router-dom'
14
13
import { UiKitClientSideRoutingProvider } from './lib/ui-kit-client-side-routing.tsx'
15
14
import { ConfirmProvider } from './context/confirm-context.tsx'
16
15
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
16
+ import { getAppConfig } from './lib/utils.ts'
17
17
18
18
// Initialize the API client
19
19
client . setConfig ( {
20
- baseUrl : import . meta . env . VITE_BASE_API_URL ,
20
+ baseUrl : getAppConfig ( ) . BASE_API_URL ,
21
21
} )
22
22
23
23
createRoot ( document . getElementById ( 'root' ) ! ) . render (
Original file line number Diff line number Diff line change 29
29
" openapi-ts.config.ts" ,
30
30
" tailwind.config.ts" ,
31
31
" vitest.config.ts" ,
32
- " vitest.setup.ts"
32
+ " vitest.setup.ts" ,
33
+ " ./global.d.ts"
33
34
],
34
35
"exclude" : [" node_modules" ]
35
36
}
You can’t perform that action at this time.
0 commit comments