Deployment
This guide covers deploying Pocket Money to Cloudflare Pages.
Prerequisites
Complete the Installation steps first.
Create Production Database
If you haven't already, copy the config template and create a database:
cp wrangler.toml.example wrangler.toml
wrangler d1 create pocket-money-db
Update wrangler.toml with the database ID from the command output.
Set Production Secrets
wrangler secret put SESSION_SECRET
Enter a secure random string when prompted.
Run Production Migrations
npm run db:migrate:prod
Deploy
Manual Deployment
npm run build
wrangler pages deploy .svelte-kit/cloudflare
Your app will be available at a *.pages.dev URL.
Automatic Deployment with GitHub Actions
The repository includes a GitHub Actions workflow that automatically deploys to Cloudflare Pages when you push to the main branch. This ensures the deployed version always matches the code on GitHub.
Required Secrets
Set up the following secrets in your GitHub repository (Settings → Secrets and variables → Actions):
| Secret | Description |
|---|---|
CLOUDFLARE_API_TOKEN |
API token with Cloudflare Pages: Edit and D1: Edit permissions. See below for setup instructions. |
CLOUDFLARE_ACCOUNT_ID |
Your Cloudflare account ID. Find it on any Cloudflare dashboard page in the right sidebar. |
Creating the API Token
- Go to Cloudflare Dashboard → API Tokens
- Click Create Token
- Click Create Custom Token
- Give the token a name (e.g., "Pocket Money Deploy")
- Add the following Permissions:
- Account | Cloudflare Pages | Edit
- Account | D1 | Edit (required for database migrations)
- Under Account Resources, select your account
- Under Zone Resources, select "All zones" or your specific zone (if using a custom domain)
- Click Continue to summary → Create Token
- Copy the token immediately (it won't be shown again)
D1 Permission Required
The D1 Edit permission is required for the deployment workflow to run database migrations automatically. Without this permission, migrations will fail silently and new database schema changes won't be applied.
How It Works
- On every push to
main, the CI workflow runs (lint, type check, tests, build) - If all checks pass, the deploy workflow:
- Builds the app
- Runs any pending database migrations
- Deploys to Cloudflare Pages
- The deployment URL will be shown in the Actions log
Set Up Recurring Payments
The app has an endpoint /api/cron that processes recurring payments. You need to call this endpoint daily for allowances to be deposited automatically.
Option A: GitHub Actions (Recommended)
If you've forked this repo to GitHub, you can use the included GitHub Action:
- Go to your repository on GitHub
- Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
CRON_URL - Value:
https://your-app.pages.dev/api/cron - Click Add secret
The workflow runs daily at 6:00 AM UTC. You can also trigger it manually from the Actions tab.
Option B: External Cron Service
Use a free service like cron-job.org to call your endpoint daily:
GET https://your-app.pages.dev/api/cron
Option C: Manual
Visit /api/cron in your browser when you want to process recurring payments.
Custom Domain
To use a custom domain:
- Go to Cloudflare Dashboard → Pages → your project
- Click Custom domains
- Add your domain and follow the DNS setup instructions
Troubleshooting
"Database not available" errors
Ensure your wrangler.toml has the correct database ID and the database has been created.
Migrations fail
Check that you're running the correct migration command (local vs production). Run migrations with --remote flag for production:
wrangler d1 execute pocket-money-db --remote --file=./migrations/0001_initial.sql
Login issues
Clear your browser cookies for the app domain and try again.