Overview
ScreenPulse uses Angular’s environment system for configuration management. This guide explains how to configure API endpoints, switch between development and production environments, and customize application settings.Environment Files
ScreenPulse uses TypeScript-based environment files located insrc/environments/:
Angular automatically selects the appropriate environment file based on your build configuration. You never need to manually change imports.
Development Configuration
Local Development Setup
File:src/environments/environment.development.ts
This configuration is used when running ng serve or npm start:
environment.development.ts
Configuration Properties
Base URL for favorites management API endpoints.Development:
http://localhost:9000/api/favoritesEndpoints:GET /- Fetch user’s favorite itemsPOST /- Add new favoriteDELETE /:id- Remove favoritePATCH /:id- Update favorite notes/reviews
Base URL for OMDB search API proxy.Development:
http://localhost:9000/api/omdbEndpoints:GET /search?title={query}&type={type}&year={year}- Search mediaGET /details?id={imdbID}- Get detailed information
Base URL for user authentication API endpoints.Development:
http://localhost:9000/api/userEndpoints:POST /register- User registrationPOST /login- User authentication (returns JWT)GET /profile- Get user profilePUT /profile- Update user profile
Production Configuration
File:src/environments/environments.production.ts
This configuration is used when building for production:
environments.production.ts
Using Environment Variables
In Angular Services
Import and use environment variables in your services:user.service.ts
In Angular Components
You can also access environment variables in components:app.component.ts
Switching Between Environments
Development Mode
Run the application in development mode:environment.development.ts and connects to localhost:9000.
Production Mode
Build the application for production:environments.production.ts and connects to the hosted backend API.
Preview Production Build
To test the production build locally:Angular Build Configuration
ScreenPulse’s build configuration is defined inangular.json:
angular.json
Key Build Settings
File Replacements
File Replacements
Angular automatically swaps environment files during build:
- Development: Uses
environment.development.ts - Production: Uses
environments.production.ts
Build Optimization
Build Optimization
Production builds include:
- Ahead-of-Time (AOT) compilation
- Build optimizer
- Minification
- Tree-shaking
- Output hashing for cache busting
- Just-in-Time (JIT) compilation
- Source maps for debugging
- Named chunks for easier debugging
- No optimization (faster rebuilds)
Build Budgets
Build Budgets
ScreenPulse enforces bundle size limits:If your bundle exceeds these limits, the build will warn or fail.
Running Local Backend
To develop with a local backend API:Configure Backend
Custom Environment Configuration
You can create additional environment configurations for staging, testing, etc.Create Staging Environment
CORS Configuration
If you encounter CORS issues during development:Using Angular Proxy
Createproxy.conf.json in the project root:
proxy.conf.json
package.json:
package.json
environment.development.ts
Environment Best Practices
Never Commit Secrets
Environment files are committed to Git. Never store:
- API keys
- Database passwords
- JWT secrets
- Private credentials
.env file for secrets.Keep URLs DRY
Define base URLs once in environment files:
Test Both Environments
Always test:
- Development mode (
ng serve) - Production build (
ng build && serve)
Document API Changes
When backend APIs change:
- Update environment URLs
- Update service code
- Update API documentation
- Test all affected features
Troubleshooting
Wrong environment file is being used
Wrong environment file is being used
Problem: Changes to environment file don’t appear in the app.Solution:
- Stop the dev server (Ctrl+C)
- Clear Angular cache:
- Restart the dev server:
- Hard refresh the browser (Ctrl+Shift+R)
API requests failing with CORS errors
API requests failing with CORS errors
Problem: Browser blocks API requests due to CORS policy.Solution:Option 1: Configure backend CORS (recommended)Option 2: Use Angular proxy
See CORS Configuration above.
Environment changes not reflected in build
Environment changes not reflected in build
Problem: Production build still uses old environment values.Solution:
- Delete the dist folder:
- Rebuild:
- Verify the correct environment file is being used:
Can't connect to local backend
Can't connect to local backend
Problem: Frontend can’t connect to backend at localhost:9000.Solution:
- Verify backend is running:
- Check backend logs for errors
-
Ensure
environment.development.tshas correct URL:
- Check browser console for error details
Next Steps
Development Workflow
Learn about npm scripts, hot reload, and Storybook
Architecture Overview
Understand how ScreenPulse is structured