Load env var for api url into ui for production

This commit is contained in:
2025-04-14 23:37:47 -04:00
parent 9ad87fbac5
commit c2e9e098ed
5 changed files with 9 additions and 3 deletions

View File

@@ -10,6 +10,7 @@
</head>
<body>
<div id="root"></div>
<script src="./config.js"></script>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>

View File

@@ -0,0 +1,3 @@
window.__CONFIG__ = {
API_URL: '${VITE_API_URL}'
};

View File

@@ -1,4 +1,5 @@
const baseUrl = import.meta.env.VITE_API_URL || 'http://localhost:8080/api';
// @ts-expect-error The window.__CONFIG__ only exists in production
const baseUrl = window.__CONFIG__?.API_URL || import.meta.env.VITE_API_URL || 'http://localhost:8080/api';
export async function getRequest(endpoint: string, params: Record<string, any> = {}): Promise<Response> {
Object.keys(params).forEach((key) => params[key] === undefined && delete params[key]);