Overview
The Biblioteca Virtual Frontend uses Angular’s environment configuration system to manage settings across different deployment environments. Each environment has its own configuration file.Environment Files
The application includes three environment configurations:Environment Types
Development Environment
File:src/environments/environment.ts
Used for local development with the backend running on localhost.
- Production:
false - API URL:
http://localhost:8080
Production Environment (Docker)
File:src/environments/environment.prod.ts
Used for Docker-based deployments where frontend and backend are in the same network.
- Production:
true - API URL:
http://biblioteca-backend:8080(internal Docker network)
The
biblioteca-backend hostname refers to the backend service name in Docker Compose networking.Netlify Environment
File:src/environments/environment.netlify.ts
Used for Netlify deployments connecting to the backend hosted on Render.
- Production:
true - API URL:
https://biblioteca-virtual-backend-44v7.onrender.com
Building for Different Environments
Angular Configuration
The environment configurations are referenced inangular.json:
Using Environment Variables
Import and use the environment configuration in your services:Adding New Environment Variables
Environment-Specific Features
Production Mode
Whenproduction: true, Angular enables:
- Ahead-of-Time (AOT) compilation
- Production optimizations
- Reduced bundle size
- Disabled debugging tools
API URL Configuration
TheapiUrl determines the backend endpoint:
| Environment | API URL | Use Case |
|---|---|---|
| Development | http://localhost:8080 | Local development |
| Production | http://biblioteca-backend:8080 | Docker deployment |
| Netlify | https://biblioteca-virtual-backend-44v7.onrender.com | Cloud deployment |
Runtime Configuration
For dynamic runtime configuration, consider using:Environment Variables in Docker
Configuration Service
Create a configuration service that loads settings at runtime:Best Practices
- Never commit secrets: Keep sensitive data out of environment files
- Use meaningful names: Make variable names descriptive
- Document changes: Update documentation when adding variables
- Validate URLs: Ensure API endpoints are accessible
- Test each environment: Verify builds work for all configurations
Troubleshooting
Wrong API URL
If the application connects to the wrong backend:- Check the build configuration used
- Verify the correct environment file is being used
- Clear build cache:
rm -rf dist/
Environment Not Loading
Ensure file replacements are configured correctly inangular.json.
CORS Errors
If you encounter CORS errors, verify:- The backend allows the frontend origin
- The API URL is correctly configured
- Network connectivity between services