STEPS:
- Get an OpenStates API key
- Sign up / request an API key at https://v3.openstates.org/. Copy the API key — you'll need it for the backend.
- Backend setup
cd backend
npm install (MIGHT NEED TO npm install dotenv if it doesn't pick it up)
cp .env.example .env
node server.js
Notes:
-
server.jsloads environment variables withdotenv(require('dotenv').config()). If you seeServer missing OPENSTATES_API_KEY, make surebackend/.envexists and containsOPENSTATES_API_KEYor export the env var in your shell before starting the server:OPENSTATES_API_KEY="your_key" node server.js
- Frontend setup
cd frontend npm install
Create frontend .env from the example. By default the project uses the server proxy so you do not have to put your key in the frontend.
cp .env.example .env
If you leave VITE_USE_SERVER_PROXY=true (recommended), the frontend will call the backend proxy at /api/events and /api/people.geo.
If you set VITE_USE_SERVER_PROXY=false you must also add your OpenStates key to frontend/.env as VITE_OPENSTATES_API_KEY (NOT recommended for production).
npm run dev
The Vite dev server runs (by default) on http://localhost:5173 and is configured to proxy /api/* to http://localhost:3000 (see frontend/vite.config.js). Ensure the backend is running on port 3000 before using the app.
- How the app works (quick)
- Representatives: type a US ZIP and click "Convert ZIP & Search". The frontend uses Zippopotam.us to resolve ZIP -> city/state/lat/lon and then calls the backend to fetch people for the location.
- Events: type a US ZIP and click "Convert ZIP & Search Events". The frontend converts ZIP -> state (full state name) and then calls the backend proxy
/api/events?jurisdiction=<StateName>. The backend also implements a fallback that can look up jurisdiction by point and call/events?jurisdiction=...if needed.
- Common troubleshooting
- 404 / Cannot GET /api/.. from the browser: make sure your backend is running on port 3000 and Vite proxy is enabled (it is by default in
vite.config.js). If another process is listening on port 3000, stop it or change the backend port and update the proxy. - 500 Server missing OPENSTATES_API_KEY: set
OPENSTATES_API_KEYinbackend/.envor export it in your shell before starting the backend. - Blank page after search / UI crashes: open the browser console and paste the error here. The UI is defensive against upstream HTML in event descriptions (it strips tags) to avoid layout breakage. If you want formatted descriptions, we can sanitize HTML with a library like DOMPurify.
- Development notes and configuration
- Change how many events are shown in the Events UI with the "Show: N events" input.
- To call OpenStates directly from the frontend (not recommended), set
VITE_USE_SERVER_PROXY=falseinfrontend/.envand putVITE_OPENSTATES_API_KEY=your_keyinfrontend/.env. Restart the dev server after editing.env. - Keep your real
.envfiles out of version control. The repo contains.env.examplefiles and.gitignoreentries in bothfrontend/andbackend/to help with this.