File tree 5 files changed +22
-3
lines changed
5 files changed +22
-3
lines changed Original file line number Diff line number Diff line change
1
+ VITE_APP_LOGO_URL = " "
2
+ VITE_API_URL = " "
3
+ VITE_APP_TITLE = " "
Original file line number Diff line number Diff line change @@ -7,11 +7,12 @@ import {ToastProvider} from "@/components/ui/toast.tsx";
7
7
import { Toaster } from "@/components/ui/toaster.tsx" ;
8
8
import Logo from './assets/logo.png' ;
9
9
import { Separator } from "@/components/ui/separator.tsx" ;
10
+ import getConfig from "@/config.ts" ;
10
11
11
12
const App : React . FC = ( ) => {
12
13
const [ blueprints , setBlueprints ] = useState < Blueprint [ ] > ( [ ] ) ;
13
14
useEffect ( ( ) => {
14
- document . title = window . VITE_APP_TITLE || 'Power - Starters' ;
15
+ document . title = getConfig ( ' VITE_APP_TITLE' ) || 'Power - Starters' ;
15
16
fetchBlueprints ( ) . then ( setBlueprints ) ;
16
17
} , [ ] ) ;
17
18
@@ -35,7 +36,7 @@ const App: React.FC = () => {
35
36
}
36
37
37
38
const getLogo = ( ) => {
38
- const logoUrl = window . VITE_APP_LOGO_URL ;
39
+ const logoUrl = getConfig ( ' VITE_APP_LOGO_URL' )
39
40
return (
40
41
< img src = { logoUrl || Logo } alt = "logo" className = "h-12" />
41
42
) ;
Original file line number Diff line number Diff line change 1
1
import axios , { AxiosError , AxiosResponse } from 'axios' ;
2
+ import getConfig from "@/config.ts" ;
2
3
3
4
export const API_BASE_URL =
4
- window . VITE_API_URL || 'http://localhost:3000 ' ;
5
+ getConfig ( ' window.VITE_API_URL' ) || 'http://localhost:8000 ' ;
5
6
6
7
interface Blueprint {
7
8
type : string ;
Original file line number Diff line number Diff line change
1
+ // src/utils/config.js
2
+ function getConfig ( key : string ) {
3
+ // Check if the app is running in production
4
+ if ( import . meta. env . PROD ) {
5
+ // Production environment: Read from global window object
6
+ return window [ key ] ;
7
+ } else {
8
+ // Development environment: Use Vite's import.meta.env
9
+ return import . meta. env [ key ] ;
10
+ }
11
+ }
12
+
13
+ export default getConfig ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ declare global {
4
4
VITE_APP_LOGO_URL ?: string ;
5
5
VITE_API_URL ?: string ;
6
6
VITE_APP_TITLE ?: string ;
7
+ [ key : string ] : any ;
7
8
}
8
9
}
9
10
You can’t perform that action at this time.
0 commit comments