This guide covers local development testing and production deployment to Cloudflare Workers.
Make sure you’ve completed the Setup Guide first!
You should have:
npm install)wrangler.toml with your settingsTest your streak card locally before deploying to production.
Create a .dev.vars file for local development (this file is already in .gitignore):
cat > .dev.vars << 'EOF'
# Local development environment variables
# Replace with your actual GitHub token
GITHUB_TOKEN=your_github_token_here
EOF
Replace your_github_token_here with your actual GitHub Personal Access Token from the setup guide.
Example .dev.vars:
GITHUB_TOKEN=github_pat_YOURTOKENID
Run the development server:
npm run dev
You should see output like:
⛅️ wrangler 3.114.15
-----------------------------------------------
⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:8787
⎔ Listening on http://localhost:8787
The worker is now running locally on http://localhost:8787!
Leave this terminal running while you test.
Now test your endpoints locally before deploying to production.
Open a new terminal (keep npm run dev running in the first one) and test:
curl http://localhost:8787/health
Expected output:
{"ok":true}
✅ If you see this, the worker is running correctly!
Test the SVG generation:
curl http://localhost:8787/streak.svg
You should see SVG XML output like:
<svg width="800" height="220" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%">
...
</linearGradient>
</defs>
...
<text>124</text>
...
</svg>
Open your browser and go to:
http://localhost:8787/streak.svg
You should see your streak card rendered! 🎉
Check that it shows:
Save the SVG to inspect it:
curl http://localhost:8787/streak.svg -o local-streak.svg
Open local-streak.svg in your browser or editor to verify it looks correct.
Look at your terminal where npm run dev is running. You should see logs like:
[wrangler:inf] GET /streak.svg 200 OK (524ms)
If you see errors, check the troubleshooting section below.
When you’re done testing locally, press Ctrl+C in the terminal running npm run dev.
Once local testing passes, deploy to Cloudflare Workers production.
If you haven’t already, authenticate Wrangler:
npx wrangler login
This opens a browser window. Click Allow to authorize Wrangler.
Set your GitHub token as a production secret:
npx wrangler secret put GITHUB_TOKEN
When prompted, paste your GitHub Personal Access Token and press Enter.
Expected output:
🌀 Creating the secret for the Worker "your-streak-card"
✨ Success! Uploaded secret GITHUB_TOKEN
Note: This is separate from the .dev.vars file. Production secrets are stored securely in Cloudflare.
Deploy your worker:
npm run deploy
Or directly with Wrangler:
npx wrangler deploy
You’ll see output like:
⛅️ wrangler 3.114.15
-----------------------------------------------
Total Upload: 12.02 KiB / gzip: 3.40 KiB
Your worker has access to the following bindings:
- KV Namespaces:
- STREAK_KV: 710955b2dYYY3aa0761bXXXb
- Vars:
- GITHUB_USERNAME: "your-username"
Uploaded your-streak-card (4.46 sec)
Deployed your-streak-card triggers (0.34 sec)
https://your-streak-card.your-subdomain.workers.dev
Current Version ID: 872ee407-12f8-480d-9019-10b7e914e565
🎉 Deployment successful!
Copy your production URL from the output. It will look like:
https://your-streak-card.your-subdomain.workers.dev
Test your production deployment to make sure everything works.
curl https://your-streak-card.your-subdomain.workers.dev/health
Expected:
{"ok":true}
curl https://your-streak-card.your-subdomain.workers.dev/streak.svg
Should return SVG XML.
Open in your browser:
https://your-streak-card.your-subdomain.workers.dev/streak.svg
You should see your streak card! 🔥
Verify caching headers are set correctly:
curl -I https://your-streak-card.your-subdomain.workers.dev/streak.svg
Look for:
HTTP/2 200
Content-Type: image/svg+xml
Cache-Control: public, max-age=0, s-maxage=21600, stale-while-revalidate=86400
✅ All tests passing? Your worker is live!
README.md## GitHub Streak

Replace the URL with your actual worker URL.
GitHub caches images. To force a refresh, add a version parameter:

Increment v=1 to v=2, v=3, etc. to force GitHub to re-fetch.
Note: The worker ignores query parameters, so this only affects GitHub’s cache.
<img src="https://your-streak-card.your-subdomain.workers.dev/streak.svg" alt="GitHub Streak" />
Want a custom domain instead of *.workers.dev?
streak.yourdomain.com/*Now your streak card will be available at:
https://streak.yourdomain.com/streak.svg
Made changes to the code? Redeploy:
npm run deploy
Changes take effect immediately (within seconds globally).
See real-time logs:
npx wrangler tail
This streams logs from production. Press Ctrl+C to stop.
You’ll see:
Problem: KV namespace not properly configured.
Fix:
wrangler.toml has the correct KV namespace IDnpx wrangler kv:namespace listid and preview_id are setProblem: GitHub token is missing or invalid.
Fix:
npx wrangler secret listnpx wrangler secret put GITHUB_TOKENread:user permissionProblem: Wrangler not logged in.
Fix:
npx wrangler login
Problem: First request failed and no cached data exists.
Fix:
wrangler.tomlnpx wrangler tailProblem: Edge cache holding old version.
Fix:
?v=2Problem: KV namespace binding missing in production.
Fix:
wrangler.toml has KV configurationnpm run deployProblem: Secret not set in production.
Fix:
npx wrangler secret put GITHUB_TOKEN
Enter your token when prompted.
Possible causes:
wrangler.tomlFix:
wrangler.toml# Start local dev server
npm run dev
# Test health endpoint locally
curl http://localhost:8787/health
# Test SVG endpoint locally
curl http://localhost:8787/streak.svg
# Save SVG locally
curl http://localhost:8787/streak.svg -o test.svg
# Login to Cloudflare (first time)
npx wrangler login
# Create KV namespace
npx wrangler kv:namespace create "STREAK_KV"
# Set production secret
npx wrangler secret put GITHUB_TOKEN
# Deploy to production
npm run deploy
# View production logs
npx wrangler tail
# List secrets
npx wrangler secret list
# Delete a secret
npx wrangler secret delete GITHUB_TOKEN
# Test health endpoint
curl https://your-worker.workers.dev/health
# Test SVG endpoint
curl https://your-worker.workers.dev/streak.svg
# Check HTTP headers
curl -I https://your-worker.workers.dev/streak.svg
# Save production SVG
curl https://your-worker.workers.dev/streak.svg -o production.svg
Before going live, verify:
npm run dev){"ok":true}npx wrangler secret put GITHUB_TOKEN)npm run deploy)Your streak card is live! 🎉
src/index.ts| ← Back to Setup Guide | Back to Index |