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:
31
worklenz-frontend/src/config/env.ts
Normal file
31
worklenz-frontend/src/config/env.ts
Normal 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(),
|
||||
};
|
||||
Reference in New Issue
Block a user