Configurable API Base URL (Frontend)
Use a single source of truth for the API base URL in the frontend so port/host changes don't require editing many files.
Steps
- •Add
VITE_API_URL(or equivalent) to.env.examplewith a placeholder (e.g.http://localhost:3000). - •Create a shared client (e.g.
src/utils/api.tsorapi.ts) that usesimport.meta.env.VITE_API_URLfor the base URL. - •Replace direct
fetch/axios calls with this client so all requests go through one place. - •Do not create or modify
.envin the repo. Document that users should copy.env.exampleto.envfor local use.
Do Not
- •Hardcode the host/port in multiple files.
- •Create or commit
.env(only.env.exampleand docs).
Integration
- •Works with
environment-filesskill (no.envin repo, only.env.example).