Skip to main content
The DeployStack frontend uses a sophisticated environment variable system that seamlessly works across development and production environments. This system supports both Vite’s build-time variables and Docker runtime variables for maximum flexibility.

Overview

The frontend environment system consists of two layers:
  1. Development Environment: Uses Vite’s built-in environment variable support with .env files
  2. Production Environment: Uses Docker runtime variables that are injected at container startup
This dual approach ensures that:
  • Developers can work with standard .env files during development
  • Production deployments can inject variables at runtime without rebuilding the application
  • The same codebase works seamlessly in both environments

Environment Variable Types

Vite Environment Variables (Development)

During development, Vite processes environment variables that start with VITE_ prefix:

Runtime Environment Variables (Production)

In production Docker containers, variables are injected at runtime via the env-config.sh script:

Current Environment Variables

Core Application Variables

VariableDescriptionDefault ValueRequired
VITE_DEPLOYSTACK_BACKEND_URLBackend API base URLhttp://localhost:3000Yes
VITE_APP_TITLEApplication title displayed in UIDeployStackYes

Development Setup

Environment Files

Create environment files in the services/frontend directory:

.env (Base Configuration)

.env.local (Local Overrides)

Environment File Priority

Vite loads environment files in this order (higher priority overrides lower):
  1. .env.local (highest priority, gitignored)
  2. .env.development.local
  3. .env.development
  4. .env (lowest priority)

Development Example

Production Deployment

Docker Environment Variables

The production Docker container uses the env-config.sh script to generate runtime environment variables:

Docker Compose Example

Using Environment Variables in Code

Accessing Variables

Use the utility functions from @/utils/env for consistent access:

Component Usage Example

Service Layer Example

Adding New Environment Variables

Step 1: Update TypeScript Definitions

Add the new variable to env.d.ts:

Step 2: Add to Environment Files

Add to your .env file:

Step 3: Update Docker Configuration (if needed)

For non-VITE_ prefixed variables, update env-config.sh:

Step 4: Use in Code

Environment Variable Naming Conventions

Development (Vite) Variables

  • Must start with VITE_ prefix to be accessible in the browser
  • Use SCREAMING_SNAKE_CASE format
  • Be descriptive and specific

Production Runtime Variables

  • Can include both VITE_ prefixed and custom variables
  • VITE_ variables are automatically processed
  • Custom variables need to be explicitly added to env-config.sh

Best Practices

Security

  1. Never expose sensitive data in environment variables accessible to the browser
  2. Use backend proxy for sensitive API keys and secrets
  3. Validate environment variables before using them

Performance

  1. Cache environment variables instead of calling getEnv() repeatedly
  2. Use computed properties in Vue components for reactive environment values

Development

  1. Use .env.local for personal development settings
  2. Document all environment variables in this guide
  3. Provide sensible defaults in .env file
  4. Test both development and production environment setups

Troubleshooting

Common Issues

Variable Not Accessible in Browser

Problem: Environment variable is undefined in the browser Solution: Ensure the variable name starts with VITE_

Variable Not Updated in Production

Problem: Environment variable changes don’t reflect in production Solutions:
  1. Restart the Docker container
  2. Check if the variable is properly passed to the container
  3. Verify env-config.sh processes the variable correctly

TypeScript Errors

Problem: TypeScript complains about unknown environment variables Solution: Update env.d.ts with the new variable definition

Development vs Production Differences

Problem: Different behavior between development and production Solutions:
  1. Use the same variable names in both environments
  2. Test with Docker locally: docker build -t test . && docker run -e VITE_VAR=value test
  3. Use getAllEnv() to debug variable values

Validation Utility

Create a validation utility for critical environment variables: