A real-time demo application built with SvelteKit 5, TypeScript, Tailwind CSS, and Convex (self-hosted). Features real-time messaging, task management, and Server-Sent Events (SSE).
Clone and install dependencies:
npm install
Configure environment variables:
cp .env.example .env.local
Edit .env.local
and set your self-hosted Convex URL:
PUBLIC_CONVEX_URL=http://your-convex-server:8080
Start the development server:
npm run dev
Open your browser:
Navigate to http://localhost:5173
Start the Convex development server:
npx convex dev
This command will:
convex/
directoryconvex/_generated/
Configure your environment:
cp .env.example .env.local
Edit .env.local
with your self-hosted Convex server details:
# Convex Configuration
# Replace with your actual self-hosted Convex URL
CONVEX_SELF_HOSTED_URL='https://your-convex-server.com'
CONVEX_SELF_HOSTED_ADMIN_KEY='your-admin-key-here'
# Optional: Convex Deploy Key (for CI/CD)
# CONVEX_DEPLOY_KEY=your-deploy-key-here
PUBLIC_CONVEX_URL=https://your-convex-server.com
Deploy your functions:
The npx convex dev
command automatically deploys your functions, but you can also manually deploy:
npx convex deploy
The demo includes:
convex/schema.ts
)If this is your first time running the project:
npm install
npx convex dev
.env.example
to .env.local
npm run dev
http://localhost:5173
src/
āāā lib/
ā āāā components/ # Svelte components
ā ā āāā MessageList.svelte
ā ā āāā TaskList.svelte
ā ā āāā EventStream.svelte
ā ā āāā SSEEventStream.svelte
ā āāā convex.ts # Convex client setup
āāā routes/
ā āāā api/events/ # SSE endpoint
ā āāā +layout.svelte # App layout
ā āāā +page.svelte # Main demo page
āāā app.css # Tailwind styles
convex/
āāā schema.ts # Database schema
āāā messages.ts # Message functions
āāā tasks.ts # Task functions
āāā events.ts # Event functions
āāā _generated/ # Generated Convex files
npm run build
npm run preview
npx wrangler login
Configure your environment variables:
Set your Convex secrets using Wrangler:
# Set your Convex admin key (required)
npx wrangler secret put CONVEX_SELF_HOSTED_ADMIN_KEY
# Optional: Set deploy key for CI/CD
npx wrangler secret put CONVEX_DEPLOY_KEY
Update wrangler.toml:
Edit the environment variables in wrangler.toml
:
[env.production.vars]
CONVEX_SELF_HOSTED_URL = "https://your-production-convex-server.com"
PUBLIC_CONVEX_URL = "https://your-production-convex-server.com"
Deploy to Cloudflare Workers:
# Deploy to default environment
npm run deploy
# Deploy to staging
npm run deploy:staging
# Deploy to production
npm run deploy:production
Test your deployment:
# View live logs
npm run cf:tail
# Test locally with Cloudflare Workers runtime
npm run cf:dev
.env.local
for local development[env.staging.vars]
in wrangler.toml
[env.production.vars]
in wrangler.toml
wrangler secret put
for sensitive data"Failed to connect to Convex"
CONVEX_SELF_HOSTED_URL
and PUBLIC_CONVEX_URL
in .env.local
match your Convex serverCONVEX_SELF_HOSTED_ADMIN_KEY
is correctly setFunctions not updating
npx convex dev
convex/
directory structure is correctDemo mode showing instead of real-time data
Create .env.local
in your project root:
# Convex Configuration
# Replace with your actual self-hosted Convex URL
CONVEX_SELF_HOSTED_URL='https://your-convex-server.com'
CONVEX_SELF_HOSTED_ADMIN_KEY='your-admin-key-here'
# Optional: Convex Deploy Key (for CI/CD)
# CONVEX_DEPLOY_KEY=your-deploy-key-here
PUBLIC_CONVEX_URL=https://your-convex-server.com
npx convex dev
(keep running)npm run dev
(in another terminal)convex/
files - they auto-deploysrc/
files - they auto-reloadconvex/
directorynpx convex dev
convex/_generated/