Single-root JavaScript version of the project, with a Vercel-ready API route for Gemini.
Create a local env file from the example:
cp .env.example .env.localAdd your Gemini key to .env.local, then start the local server:
source .env.local && npm startOpen http://127.0.0.1:8080.
If you open index.html from another dev server such as Live Server on port 5500/5501, keep the Node server running as well because the chatbot API lives on port 8080.
The Gemini key stays server-side. Do not put it in script.js, index.html, or commit it to the repo.
- Push this project to GitHub.
- Import the repo into Vercel.
- In Vercel, open
Project Settings -> Environment Variables. - Add:
GEMINI_API_KEY= your Gemini API key - Apply it to
Production,Preview, andDevelopmentif you want it available everywhere. - Redeploy after saving the variable.
The frontend calls /ask, and vercel.json rewrites that path to the server-side function in api/ask.js, where the key is read with process.env.GEMINI_API_KEY.
- Automated tests with Node's built-in test runner:
npm test - Prompt validation and input length limits
- Security headers for the static server and Vercel function
- Basic request rate limiting for
/ask - Official source links returned with assistant answers
- Optional Google Civic Information API enrichment when
GOOGLE_CIVIC_API_KEYandDEFAULT_VOTER_ADDRESSare configured
index.html- UIstyle.css- stylingscript.js- client-side behaviorserver.js- local Node server and/askendpointapp-core.js- shared validation, source mapping, and security helpersgemini-service.js- Gemini and optional Google Civic integrationsapp.test.js- automated testsapi/ask.js- Vercel serverless Gemini endpointvercel.json- rewrite/askto the Vercel API function