Client-facing app for Campaign Lab bubbles.
This project uses a "Shadow" API strategy to handle private spatial data without committing it to the public repository.
The mock API is integrated directly into the Vite development and preview servers.
| Command | Goal | Mock API State |
|---|---|---|
npm run dev |
Local coding/testing | Active (intercepts /api/data/*) |
npm run stage |
Preview production build | Active (intercepts /api/data/*) |
npm run deploy |
Push to GitHub Pages | Bypassed (Talks to External API) |
Note on "Bypassed": In the production build, the local mock plugin is removed. The app remains fully functional, but it expects a real API service (like your Python backend) to handle the
/api/data/requests.
- Data Folder: Put your GeoJSON files in the gitignored root
/datafolder (e.g.,/data/ward/london.geojson). - Frontend: The
boundaryServicewill fetch from/api/data/ward/london.geojsonand it will just work.
To protect public administrative data, follow these strict rules:
- Status: Git-Ignored (Private to your machine).
- Packaging: NEVER bundled into production. Vite ignores this folder during
npm run build. - Use Case: This is where you store your real administrative GeoJSONs and GPKGs.
- Access: The frontend only sees this through the Mock API during local development.
- Status: Tracked by Git (Publicly visible).
- Packaging: ALWAYS bundled into production. Everything in
/publicis uploaded to GitHub and becomes publicly downloadable. - Rule: DO NOT put any sensitive or licensed boundary data in
/public.
- Data Folder: Put your GeoJSON files in the gitignored root
/datafolder (e.g.,/data/ward/london.geojson). - Frontend: Use the
boundaryServiceto fetch. It hits/api/data/ward/london.geojson, which the Vite plugin serves from your private/datafolder.
If you are running your own backend (like a separate Python app) and want to stop using the built-in mock:
You don't want the Vite plugin to "steal" the requests meant for your real server.
- Open
vite.config.ts. - Set
useMockApitofalse(or set the environment variableVITE_USE_MOCK_API=false).
When useMockApi is false, Vite proxies /api requests to your external server (defaulting to http://localhost:3001).
Update this in vite.config.ts to match your Python backend.
If you want to test the exact behavior of an external server without building your Python app yet:
npm install express cors(if not already installed).- Run
node api/server.js. - Disable the mock plugin in
vite.config.ts(as described above). - The frontend will now talk to the standalone Node server instead of the built-in Vite middleware.
Once deployed, the app will try to fetch from your-domain.com/api/data/.... You have two ways to satisfy this:
- Proxying: Use Nginx or your host's routing to point
/apito your Python backend. - External URL: Update
src/services/boundaryService.tsto use an absolute URL (e.g.,https://api.campaignlab.uk/data/...).
The /data folder is included in .gitignore. NEVER remove this from the ignore list. The frontend service is designed to be swappable, so moving from this local mock to a production Python API requires only a one-line change in src/services/boundaryService.ts.