edgebase-worker
v0.1.0
Published
EdgeBase Worker - Cloudflare Workers deployment (uses published npm packages)
Downloads
7
Readme
EdgeBase Worker - Example Deployment
This is an example deployment of EdgeBase using published NPM packages.
For External Users: This demonstrates how to use
@edgebasejs/workerand the EdgeBase CLI to deploy a complete backend to Cloudflare Workers, independently from the monorepo.
This package is the Cloudflare Workers backend only.
The admin UI is deployed separately via @edgebasejs/admin-console and connects to this worker URL.
Features
- Auth: Login/Register with email and password
- Todos CRUD: Create, read, update, delete todos
- User Isolation: Each user only sees their own todos
- Session Management: Token-based authentication
Schema & Migrations
- Schema source:
apps/worker/edgebase.schema.ts - Migrations:
apps/worker/migrations/*.sql - Worker entrypoint:
apps/worker/src/index.ts(EdgeBase worker factory)
Generate SDK + migrations after schema changes:
cd apps/worker
npx edgebase generateApply migrations to local D1:
cd apps/worker
npx edgebase migrateNote: In development, the worker can auto-initialize tables from the schema. In production, run migrations explicitly.
Quick Start
# Install dependencies
npm install
# Start worker development server
npm run dev
# Opens: http://localhost:8787 (Worker API)Start admin console separately (in another terminal):
cd ../admin-console
npm run dev
# Opens: http://localhost:3001
# First open asks for Worker URL (e.g. http://localhost:8787)Build/publish commands are available via the EdgeBase CLI:
# Start development
npm run dev
# Build for deployment
npm run build
# Deploy to Cloudflare Workers
npm run deploy
# Publish to npm
npm run publishAPI Endpoints
Auth
# Login
curl -X POST http://localhost:8787/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"password123"}'
# Register
curl -X POST http://localhost:8787/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"password123"}'Todos
TOKEN="..." # From login response
# Create todo
curl -X POST http://localhost:8787/todos \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"title":"Buy milk","completed":false}'
# Get all todos
curl http://localhost:8787/todos \
-H "Authorization: Bearer $TOKEN"
# Get single todo
curl http://localhost:8787/todos/TODOID \
-H "Authorization: Bearer $TOKEN"
# Update todo
curl -X PATCH http://localhost:8787/todos/TODOID \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"completed":true}'
# Delete todo
curl -X DELETE http://localhost:8787/todos/TODOID \
-H "Authorization: Bearer $TOKEN"Storage
Uses Cloudflare D1 (SQLite). System tables and entity tables are managed via EdgeBase migrations.
Deployment
# Build for production
npm run build
# Deploy to Cloudflare Workers
npm run deploy
# Or publish worker package
npm run publishSet environment variables in wrangler.toml for production.
About the Admin Console
The admin console is a separate deployment:
- Uses this worker via its URL
- On first start it asks for the Worker URL
- Supports login with an existing admin account
- Supports first-admin setup when no admin exists yet
Architecture
Client (React Native + Expo)
↓
EdgeBase SDK
↓
This Worker (REST API)
↓
In-Memory Storage (or D1 in production)The app communicates with this worker via HTTP. The SDK handles:
- Authentication (token management)
- Offline-first caching
- Sync logic
- Query caching
