Skip to content

Commit 7c9cca8

Browse files
committed
refactor: dashboard api base url env
1 parent 787519d commit 7c9cca8

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div id="root"></div>
1010
<script>
1111
window.APP_CONFIG = {
12-
BASE_API_URL: '${BASE_API_URL}',
12+
DASHBOARD_API_BASE_URL: '${DASHBOARD_API_BASE_URL}',
1313
}
1414
</script>
1515
<script type="module" src="/src/main.tsx"></script>

src/global.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface AppConfig {
2-
BASE_API_URL?: string
2+
DASHBOARD_API_BASE_URL?: string
33
}
44

55
declare global {

src/hooks/useSse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { invalidateQueries } from '@/lib/react-query-utils'
99
import { getAppConfig } from '@/lib/utils'
1010

11-
const baseApiUrl = getAppConfig().BASE_API_URL
11+
const baseApiUrl = getAppConfig().DASHBOARD_API_BASE_URL
1212

1313
export function useSse() {
1414
const location = useLocation()

src/lib/__tests__/utils.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { AppConfig } from '@/global'
44
describe('getAppConfig', () => {
55
const mockViteBaseApiUrl = 'https://api.mock.com'
66

7-
it('default base api url if ${BASE_API_URL}" not configured', () => {
7+
it('default base api url if ${DASHBOARD_API_BASE_URL}" not configured', () => {
88
const mockAppConfig: AppConfig = {
9-
BASE_API_URL: '${BASE_API_URL}',
9+
DASHBOARD_API_BASE_URL: '${DASHBOARD_API_BASE_URL}',
1010
}
1111

1212
Object.defineProperty(window, 'APP_CONFIG', {
@@ -16,15 +16,15 @@ describe('getAppConfig', () => {
1616

1717
const expectedConfig: AppConfig = {
1818
...mockAppConfig,
19-
BASE_API_URL: 'https://mock.codegate.ai',
19+
DASHBOARD_API_BASE_URL: 'https://mock.codegate.ai',
2020
}
2121

2222
expect(getAppConfig()).toEqual(expectedConfig)
2323
})
2424

25-
it('replace base api url if ${BASE_API_URL}" is configured', () => {
25+
it('replace base api url if ${DASHBOARD_API_BASE_URL}" is configured', () => {
2626
const mockAppConfig: AppConfig = {
27-
BASE_API_URL: mockViteBaseApiUrl,
27+
DASHBOARD_API_BASE_URL: mockViteBaseApiUrl,
2828
}
2929

3030
Object.defineProperty(window, 'APP_CONFIG', {
@@ -34,7 +34,7 @@ describe('getAppConfig', () => {
3434

3535
const expectedConfig: AppConfig = {
3636
...mockAppConfig,
37-
BASE_API_URL: mockViteBaseApiUrl,
37+
DASHBOARD_API_BASE_URL: mockViteBaseApiUrl,
3838
}
3939

4040
expect(getAppConfig()).toEqual(expectedConfig)

src/lib/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ export function sanitizeQuestionPrompt({
7373
}
7474

7575
export function getAppConfig(): AppConfig {
76-
const baseApiUrl = window.APP_CONFIG?.BASE_API_URL
76+
const baseApiUrl = window.APP_CONFIG?.DASHBOARD_API_BASE_URL
7777

78-
if (!baseApiUrl || baseApiUrl === '${BASE_API_URL}') {
78+
if (!baseApiUrl || baseApiUrl === '${DASHBOARD_API_BASE_URL}') {
7979
return {
8080
...window.APP_CONFIG,
81-
BASE_API_URL: import.meta.env.VITE_BASE_API_URL,
81+
DASHBOARD_API_BASE_URL: import.meta.env.VITE_BASE_API_URL,
8282
}
8383
}
8484

8585
return {
8686
...window.APP_CONFIG,
87-
BASE_API_URL: baseApiUrl,
87+
DASHBOARD_API_BASE_URL: baseApiUrl,
8888
}
8989
}

src/main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getAppConfig } from './lib/utils.ts'
1717

1818
// Initialize the API client
1919
client.setConfig({
20-
baseUrl: getAppConfig().BASE_API_URL,
20+
baseUrl: getAppConfig().DASHBOARD_API_BASE_URL,
2121
})
2222

2323
createRoot(document.getElementById('root')!).render(

src/vite-env.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="vite/client" />
22
interface ImportBaseApiEnv {
3-
readonly BASE_API_URL: string
3+
readonly DASHBOARD_API_BASE_URL: string
44
readonly VITE_BASE_API_URL: string
55
}

0 commit comments

Comments
 (0)