Public
Likenanosupabase-demo
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v7View latest version
Deploy nano-supabase as a serverless API on Val.town with persistent storage.
- Full PostgreSQL database running in WebAssembly
- Supabase-compatible query API
- Persistent storage using Val.town blob storage (data survives cold starts)
- CORS enabled for browser access
- Go to val.town and create a new val
- Copy the contents of
index.tsinto the editor - Important: Set the val type to HTTP using the dropdown near the val name
- Your API is instantly live at
https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run
# Install vt CLI npm install -g @valtown/vt # Login vt login # Create the val from this folder cd examples/valtown vt create my-chat-api . --no-editor-files --upload-if-exists --public # IMPORTANT: After creating, go to the val's web page and set type to "HTTP" # The CLI doesn't have an option to set the val type vt browse
| Method | Path | Description |
|---|---|---|
| GET | / | API info and available endpoints |
| GET | /conversations | List all conversations |
| POST | /conversations | Create conversation { title: string } |
| GET | /messages?conversation_id=xxx | Get messages for a conversation |
| POST | /messages | Add message { conversation_id, role, content, tokens? } |
| GET | /stats | Get usage statistics |
Use the included test script:
# Run the full test suite ./test.sh https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run
Or test manually:
# Get API info curl https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/ # Create a conversation curl -X POST https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/conversations \ -H "Content-Type: application/json" \ -d '{"title": "Test Chat"}' # Add a message (replace YOUR_CONV_ID) curl -X POST https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/messages \ -H "Content-Type: application/json" \ -d '{"conversation_id": "YOUR_CONV_ID", "role": "user", "content": "Hello!"}' # Get messages curl "https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/messages?conversation_id=YOUR_CONV_ID" # Check stats curl https://YOUR_USERNAME-YOUR_VAL_NAME.web.val.run/stats
This example includes built-in persistence using Val.town's blob storage. Data is automatically:
- Saved to blob storage after each write (POST) operation
- Restored from blob storage on cold start
The blob key is nano-supabase-chat-db. You can view/manage it in your Val.town dashboard.
The example uses a chat schema, but you can modify index.ts to:
- Add your own tables and schemas
- Implement different API endpoints
- Add authentication
- Connect to AI APIs for chat completions
"Not found" response: The val type isn't set to HTTP. Go to the val's page and change the type dropdown to "HTTP".
"Invalid version provided" error: This usually means there's a caching issue. Try:
- Delete the val and create a new one with a different name
- Clear Val.town's module cache by changing the import URL (add
?v=2)
Import errors: Make sure you're using the exact versions specified:
- PGlite:
npm:@electric-sql/pglite@0.2.17 - nano-supabase:
https://raw.githubusercontent.com/filipecabaco/nano-supabase/main/dist/index.js