Angular’s environment file system lets you define build-time constants — such as the backend API URL — that are baked into the compiled bundle. Aibar SRL App uses two environment files underDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/lucavallini/aibar-frontend/llms.txt
Use this file to discover all available pages before exploring further.
src/environments/: one for local development that points at a locally running FastAPI server, and one for production that targets the hosted backend on Render. Choosing the right file before you build ensures every service in the app talks to the correct API without any runtime configuration.
Environment Files
The two environment files live at:src/environments/environment.ts— used forng serveand development buildssrc/environments/environments.prod.ts— used for production builds
environment object shape. Every Angular service imports from ../../../environments/environment — the same relative path — which means switching backends only requires changing the value in the appropriate file, not touching any service code.
Development Environment
The development environment file (src/environments/environment.ts) is the default used by ng serve and by any build that runs with the development configuration. It sets production: false and points apiUrl at http://127.0.0.1:8000, which is the address where the Aibar FastAPI backend listens when started locally.
ng serve, Angular compiles src/main.ts using tsconfig.app.json with src/environments/environment.ts in scope. No manual selection is required — this file is always active during local development.
Production Environment
The production environment file (src/environments/environments.prod.ts) sets production: true and points apiUrl at the hosted backend on Render: https://aibar-api.onrender.com.
The Without this,
angular.json production build configuration does not yet include a fileReplacements entry to automatically swap environment.ts for environments.prod.ts. Before deploying, you must add the fileReplacements block to the production configuration in angular.json so the build system substitutes the correct file automatically:ng build will still compile the app but will bundle the development apiUrl (http://127.0.0.1:8000) into the production artifact.Where apiUrl Is Used
Every Angular service that communicates with the backend imports environment and reads environment.apiUrl as the base URL for its HTTP calls. Here is a representative example from ViajesService:
private apiUrl = \$/viajes`is repeated across all core services —CamionesService, ChoferesService, CombustibleService, MultasService, AuditoriaService, UsuariosService, and AuthService. Updating environment.apiUrl` in one place redirects the entire application.
Changing the Backend URL
To point the frontend at a different backend — for example, a staging server or a colleague’s local machine — follow these steps:Open the correct environment file
- For local development (
ng serve): editsrc/environments/environment.ts - For production builds (
ng build): editsrc/environments/environments.prod.ts
Update the apiUrl value
Replace the existing
apiUrl string with the new backend base URL. Do not include a trailing slash:Restart the dev server
Environment files are compiled into the bundle at startup. If
ng serve is already running, stop it (Ctrl+C) and restart it so the new URL is picked up:Verify the backend is reachable
Open your browser’s DevTools → Network tab, log in, and confirm that API requests are going to the new URL and returning
200 responses. If you see CORS errors, see the CORS section below.CORS
Because the frontend runs on a different origin than the backend (e.g.,http://localhost:4200 vs. http://127.0.0.1:8000), the FastAPI backend must include the frontend’s origin in its CORS allow-list.
When the frontend URL changes — such as after deploying to a Vercel domain — update the allow_origins (or equivalent) list in the backend’s app/main.py to include the new origin. Without this, the browser will block all cross-origin requests and the app will not be able to communicate with the API.
OPTIONS) requests from the new frontend origin return the correct Access-Control-Allow-Origin header.