True Baby Cost - Email Capture Worker Setup
Overview
Simple Cloudflare Worker to capture email signups from truebabycost.com. Emails are stored in Cloudflare KV and can be exported later.
Files
/workspace/stroller-app/worker/worker.js- The worker code/workspace/stroller-app/worker/wrangler.toml- Wrangler config
Deployment Steps
1. Create KV Namespace
cd /workspace/stroller-app/worker
wrangler kv:namespace create "EMAIL_SIGNUPS"This will output something like:
🌀 Creating namespace with title "truebabycost-email-EMAIL_SIGNUPS"
✨ Success! Add the following to your wrangler.toml:
kv_namespaces = [
{ binding = "EMAIL_SIGNUPS", id = "abc123..." }
]
2. Update wrangler.toml
Replace REPLACE_WITH_KV_NAMESPACE_ID with the actual ID from step 1.
3. Deploy Worker
cd /workspace/stroller-app/worker
wrangler deployThe worker will be available at:
https://truebabycost-email.<your-subdomain>.workers.dev
4. Update HTML Form
The form in index.html needs to be updated to POST to the worker. Change the form action and add JavaScript for async submission.
API
POST /
Submit an email signup.
Request:
{ "email": "user@example.com" }Or form-encoded: email=user@example.com
Response (success):
{ "success": true, "message": "Thanks for signing up!" }Response (error):
{ "success": false, "error": "Invalid email format" }Exporting Emails
To list all collected emails:
wrangler kv:key list --namespace-id=YOUR_KV_NAMESPACE_IDTo get a specific email entry:
wrangler kv:key get "email_1234567890_abc123" --namespace-id=YOUR_KV_NAMESPACE_IDTo export all emails (script):
# List all keys
keys=$(wrangler kv:key list --namespace-id=YOUR_KV_NAMESPACE_ID --json | jq -r '.[].name')
# Get each value
for key in $keys; do
wrangler kv:key get "$key" --namespace-id=YOUR_KV_NAMESPACE_ID
doneCORS
Worker accepts requests from:
- https://truebabycost.com
- https://www.truebabycost.com
- localhost (for testing)
Notes
- Emails are stored for 1 year (TTL) - export before they expire
- Email is normalized to lowercase and trimmed
- Source (referer) and timestamp are stored with each signup