Load env var for api url into ui for production
This commit is contained in:
@@ -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>
|
||||
|
||||
3
ui/public/config.template.js
Normal file
3
ui/public/config.template.js
Normal file
@@ -0,0 +1,3 @@
|
||||
window.__CONFIG__ = {
|
||||
API_URL: '${VITE_API_URL}'
|
||||
};
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user