Overview
The badges worker is a Cloudflare Worker that serves the verifieddit badge system. It handles badge creation, verification, image serving, and proxies AI detection requests. It uses D1 for persistence and KV for caching.
Repository: Sanmarcsoft/verifieddit-www (root wrangler.toml)
Bindings
D1 Databases
| Binding | Database Name | Environment |
|---|---|---|
DB | verifieddit-badges | Production |
DB | verifieddit-badges-testing | Testing |
Secrets
| Secret | Description |
|---|---|
SIGHTENGINE_API_USER | Sightengine AI detection API user |
SIGHTENGINE_API_SECRET | Sightengine AI detection API secret |
CLERK_SECRET_KEY | Clerk backend verification key |
CLERK_PUBLISHABLE_KEY | Clerk frontend key (for JWT verification) |
Routes
| Worker | Route Pattern | Environment |
|---|---|---|
verifieddit-badges | verifieddit.com/api/* | Production |
verifieddit-badges-testing | testing.matthewstevens.org/api/* | Testing |
D1 Database Schema
Core Tables
| |
D1 Operations
| |
Deployment
Production Deploy
| |
Testing Deploy
| |
Deploy via API (When Wrangler Fails)
See Cloudflare Workers SOP for API deployment method.
Setting Secrets
| |
AI Detection Proxy
The worker proxies AI detection requests to avoid CORS issues:
Client -> verifieddit.com/api/ai-detect -> Worker -> api.sightengine.com
The worker adds the Sightengine credentials server-side, so they are never exposed to the client.
Debug Endpoint
The worker includes a /__debug endpoint for version verification:
| |
This returns the deployed version and timestamp.
Testing Isolation
The testing environment uses a separate:
- D1 database (
verifieddit-badges-testing) - Worker (
verifieddit-badges-testing) - Route (
testing.matthewstevens.org/api/*) - Clerk instance (test keys:
pk_test_*)
This ensures testing never affects production data.
Preflight Checks
Before deploying to production, run the preflight script (13 checks):
- API endpoint responds
- D1 database accessible
- Badge creation works
- Badge retrieval works
- AI detection proxy works
- Clerk auth verification
- Stripe webhook responds
- CSP headers correct
- CORS headers correct
- Docker network connectivity (NAS)
- Container DNS resolution
- Health check endpoint
- Clerk publishable key present in build
Troubleshooting
- D1 binding error: Verify the D1 database ID in
wrangler.tomlmatches the actual database. Usenpx wrangler d1 listto check. - AI detect returning 403: Check Sightengine API credentials. May need to re-set secrets after a deploy.
- Old code still serving after deploy: Check for Worker versioning issues. See Cloudflare Workers SOP version management section.
- CSP errors in browser: Check
clerk-telemetry.comis in the Content-Security-Policy header. This was a known issue.