Mock Data and a One-Line baseURL Switch Let Frontend Development Run Without a Backend
Waiting for backend endpoints is one of the most common frontend blockers in full-stack projects. This pattern costs almost nothing to adopt — an `api/` directory, an axios instance, and a Vite mock plugin — and eliminates that dependency entirely, letting frontend and backend teams ship in parallel.
Frontend-backend separation is often treated as a code-organization concern, but the real bottleneck is the development timeline: frontend teams stall waiting for backend endpoints. A lightweight interface-engineering layer solves this by centralizing all API calls in an `api/` directory, configuring an axios instance with a swappable `baseURL`, and intercepting requests with MockJS through Vite during development. The frontend defines its own contract, mocks the data, and builds the full application independently. When the real backend is ready, commenting out one `baseURL` line switches every request to the live server with zero code changes elsewhere. The pattern ties together React components, react-router lazy loading, zustand state management, and the mock layer into a single workflow that decouples frontend and backend delivery schedules.
The pattern is less about tooling and more about treating the API contract as a frontend-owned artifact: the frontend defines the shape and cadence of data it needs, and the backend conforms later.
MockJS plus Vite interception is a notably simpler alternative to running a separate mock server or using service workers for local development, and it integrates directly into the existing dev-server pipeline.
The one-line `baseURL` switch is effective because it exploits axios’s instance pattern — every API module imports the same configured instance, so a single config change propagates everywhere without touching individual request functions.