Simple helper for local development: an Express proxy plus a Kotlin shared client.
Overview
- Lightweight Node server in
app.jsexposingGET /healthandPOST /generate. - Kotlin shared module provides
HttpChatClientwhich calls the proxy by default.
Quick start
- Install dependencies:
npm install- Start the server:
npm startEnvironment (PowerShell example)
$env:GEMINI_ENDPOINT = 'https://your-gemini-endpoint'
$env:GEMINI_API_KEY = 'YOUR_KEY'
npm startAPI examples
- Health check:
curl http://localhost:3000/health- Generate (proxy):
curl -X POST http://localhost:3000/generate \
-H "Content-Type: application/json" \
-d '{"prompt":"Hello"}'Kotlin usage
Use HttpChatClient from the shared module. By default it calls http://localhost:3000/generate.
val client = HttpChatClient()
val response = client.sendMessage("Hello", apiKey)Security
- Do NOT commit real API keys. Use environment variables, keystore or CI secrets.
License
- MIT
Capacitor (mobile)
- If you're building a mobile app with Capacitor, the project uses
www/as the web assets directory. - Quick commands (run from project root):
# build web assets (optional)
npm run build
# add android (only once)
npx cap add android
# copy web assets + plugins
npx cap sync android
# open Android Studio
npx cap open android- Web fetch (works in browser / web runtime):
async function generate(prompt: string) {
const res = await fetch('http://localhost:3000/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt })
});
return await res.json();
}- Native (avoid CORS) using
@capacitor-community/http:
npm install @capacitor-community/http
npx cap syncimport { Http } from '@capacitor-community/http';
async function generate(prompt: string) {
const opts = {
url: 'http://localhost:3000/generate',
headers: { 'Content-Type': 'application/json' },
data: { prompt }
};
const res = await Http.post(opts);
return res.data;
}Notes: prefer the native plugin on device to avoid CORS; never hardcode API keys in client code.
Quick summary
- A small Express helper is in
app.jsexposingGET /healthandPOST /generate. - The Kotlin shared module contains
HttpChatClientwhich defaults tohttp://localhost:3000/generate.
Run locally
- Install Node deps (already run in this workspace):
npm install- Set environment variables (preferred) or use
--endpoint/--keyin CLI/HTTP body.
- Example using environment variables (PowerShell):
$env:GEMINI_API_KEY = 'AIzaSyAc-5b06tOEjZOe_PZTEQAkqdvXnYLaPb4Y'
npm startowershell
- Health check:
curl http://localhost:3000/health- Proxy a generate request (body:
{ "prompt":"Hi" }):
curl -X POST http://localhost:3000/generate -H "Content-Type: application/json" -d '{"prompt":"Hello","endpoint":"https://your-gemini-endpoint","key":"YOUR_KEY"}'Kotlin usage
In shared code use HttpChatClient:
val client = HttpChatClient()
val response = client.sendMessage("Hello", apiKey)By default endpointUrl is optional — HttpChatClient will call http://localhost:3000/generate.
Security
- Do NOT commit real API keys.
gradle.propertieshad a committed key which has been removed. - Prefer storing secrets in environment variables, Android/iOS keystores, or CI/CD secret stores.