Cloudflare Workers Debugging
Real-Time Log Commands
npx wrangler tail pitchey-api-prod --format pretty
npx wrangler tail pitchey-api-prod --status error
npx wrangler tail pitchey-api-prod --search "/api/browse"
npx wrangler tail pitchey-api-prod --search "/api/ndas"
npx wrangler tail pitchey-api-prod --search "/api/auth"
npx wrangler tail pitchey-api-prod --search "/api/pitches"
npx wrangler tail pitchey-api-prod --method POST
npx wrangler tail pitchey-api-prod --method GET
npx wrangler tail pitchey-api-prod --status error --search "/api/auth"
npx wrangler tail pitchey-api-prod --method POST --search "/api/ndas"
Local Debugging with Breakpoints
npx wrangler dev --remote
Test Endpoints Directly
curl https://pitchey-api-prod.ndlovucavelle.workers.dev/health
curl -X GET "https://pitchey-api-prod.ndlovucavelle.workers.dev/api/user" \
-H "Cookie: better-auth.session_token=YOUR_TOKEN"
curl -X POST "https://pitchey-api-prod.ndlovucavelle.workers.dev/api/pitches" \
-H "Content-Type: application/json" \
-H "Cookie: better-auth.session_token=YOUR_TOKEN" \
-d '{"title": "Test Pitch", "description": "Testing"}'
curl "https://pitchey-api-prod.ndlovucavelle.workers.dev/api/browse?tab=trending&limit=4"
curl "https://pitchey-api-prod.ndlovucavelle.workers.dev/api/browse?tab=new&limit=4"
Common Error Patterns
ReferenceError: X is not defined
- Check imports at top of file
- Verify variable is in scope where used
- Check if variable was renamed but not updated everywhere
- Look for typos in variable names
TypeError: Cannot read property 'X' of undefined
- Add null checks before accessing properties
- Verify API response shape matches expectations
- Check if async data loaded before access
500 Internal Server Error
npx wrangler tail pitchey-api-prod --status error --format pretty
401 Unauthorized
- Better Auth uses cookies, NOT JWT headers
- Ensure
credentials: 'include' in frontend fetch
- Check session hasn't expired
- Verify cookie domain matches
404 Not Found
- Check route is registered in Worker
- Verify HTTP method matches (GET vs POST)
- Check for typos in endpoint path
CORS Errors
- Frontend must use
credentials: 'include'
- Worker must return
Access-Control-Allow-Credentials: true
- Origin must match exactly (including https://)
Database Connection Errors
- Always use:
postgres(env.HYPERDRIVE.connectionString)
- Never use direct Neon URL or pooler URL with Hyperdrive
- Check Neon dashboard for connection limit issues
Session/Auth Errors (Better Auth)
- Uses cookies, NOT Authorization header
- Session cookie name:
better-auth.session_token
- Must include credentials in fetch calls
- Check cookie SameSite and Secure attributes
Quick Diagnostic Sequence
curl -I https://pitchey-api-prod.ndlovucavelle.workers.dev/health
npx wrangler tail pitchey-api-prod --status error --format pretty
curl "https://pitchey-api-prod.ndlovucavelle.workers.dev/api/[endpoint]"
npx wrangler dev --remote