Enhance Docker deployment with environment variable configuration

- Added environment variable setup in docker-compose.yml for VITE_API_URL.
- Introduced update-docker-env.sh script to create/update .env file for local and remote deployments.
- Updated Dockerfile to dynamically create env-config.js during build.
- Modified frontend to load environment configuration from env-config.js.
- Refactored API client to use centralized config for API URL.
This commit is contained in:
chamiakJ
2025-04-28 11:32:44 +05:30
parent 9c27c41a5e
commit 2a3ae31e4e
9 changed files with 140 additions and 9 deletions

View File

@@ -0,0 +1,31 @@
/**
* Environment configuration
* Reads from window.VITE_API_URL (set by env-config.js)
* Falls back to import.meta.env.VITE_API_URL (set during build time)
* Falls back to a development default
*/
declare global {
interface Window {
VITE_API_URL?: string;
}
}
export const getApiUrl = (): string => {
// First check runtime-injected environment variables
if (window.VITE_API_URL) {
return window.VITE_API_URL;
}
// Then check build-time environment variables
if (import.meta.env.VITE_API_URL) {
return import.meta.env.VITE_API_URL;
}
// Default for development
return 'http://localhost:3000';
};
export default {
apiUrl: getApiUrl(),
};