This repo contains the backend component used by the GenAI-Powered In-Car Voice Assistant demo which connects the client application to PowerSync and provides endpoints for token generation, public JWKS keys and handling writes to the source MongoDB Atlas database.
- Use nvm to configure the Node.js environment or download/install Node.js v20
- Install dependencies
pnpm install
- Create an
.env
file and set the following variables
POWERSYNC_PUBLIC_KEY=
POWERSYNC_PRIVATE_KEY=
MONGO_URI=mongodb+srv://<username>:<password>@<cluster>/<database_name>?appName=<app_name>
NODE_ENV=development
Request a new public/private key from PowerSync Support.
- Build
pnpm build
- Run
pnpm start
This stars the backend locally and uses the default express functions to start and listen for incoming requests on port http://localhost:3000.
This application is configured to run on GoogleCloud Functions. Follow the steps below to deploy it.
- Authenticate with GCP
gcloud auth login
- Set your project:
gcloud config set project YOUR_PROJECT_ID
- Deploy the function with environment variables
gcloud functions deploy api \
--entry-point api \
--runtime nodejs20 \
--trigger-http \
--allow-unauthenticated \
--gen2 \
--set-env-vars POWERSYNC_PUBLIC_KEY=<value>,POWERSYNC_PRIVATE_KEY=<value>,MONGO_URI=<value>,NODE_ENV=production
Get the function URL: gcloud functions describe api --format='value(httpsTrigger.url)'
- Token:
curl -X GET https://REGION-PROJECT_ID.cloudfunctions.net/api/token
- JWKS:
curl -X GET https://REGION-PROJECT_ID.cloudfunctions.net/api/jwks
- POST Data:
curl -X PUT -H "Content-Type: application/json" -d '{"key": "value"}' https://REGION-PROJECT_ID.cloudfunctions.net/api/data