This monorepo contains the Cloudflare worker in timeline-events-worker/timeline-events.
This Cloudflare Worker fetches global news and converts it into timeline events with significance scoring.
npm install -g wranglerwrangler login% cd timeline-events-worker/timeline-events
# Create your local .dev.vars file
NEWS_API_KEY=your_actual_api_key_here- Go to newsapi.org
- Sign up for a free account (1000 requests/month)
- Get your API key
- Add it to your
.dev.varsfile locally
# Set the API key as a secret in Cloudflare (production)
wrangler secret put NEWS_API_KEY
# You'll be prompted to enter the key securely
# For development environment
wrangler secret put NEWS_API_KEY --env development# Test locally first (reads from .env file)
wrangler dev
# Deploy to development (uses Cloudflare secrets)
wrangler deploy --env development
# Deploy to production (uses Cloudflare secrets)
wrangler deploy --env productionLocal Development:
- Create
.dev.varsfile for local testing (never commit this!) - The
.dev.varsfile is in.gitignoreso it won't be pushed to GitHub - Use
wrangler devto test locally with your.dev.varsfile
Production Deployment:
- Use
wrangler secret putto securely store API keys in Cloudflare - Secrets are encrypted and never visible in your code or GitHub
- Different secrets for development/production environments
What gets committed to GitHub:
- ✅
worker.js(no secrets in the code) - ✅
wrangler.toml(no secrets, just configuration) - ✅
.gitignore(protects your actual.envfile) - ❌
.dev.vars(your actual secrets - protected by .gitignore)
The worker scores news events 1-10 based on:
Keywords (modify SIGNIFICANCE_KEYWORDS):
Source Importance (modify SIGNIFICANT_SOURCES):
Filter Threshold: Change minimum significance
.filter(article => article.significance >= 5) // Adjust this numberEvent Limit: Change max events returned
.slice(0, 20); // Adjust this numberCache Duration: Change how long responses are cached (currently 5 minutes)
const CACHE_TTL = 300; // SecondsKeywords: Add your own important keywords
const SIGNIFICANCE_KEYWORDS = {
10: [..., 'your-important-keyword'],
// ...
};Once deployed, your API will be available at:
https://timeline-events-api.your-subdomain.workers.dev/
Update your timeline configuration to use this URL:
const apiUrl = 'https://timeline-events-api.your-subdomain.workers.dev/';Test your worker locally:
wrangler devThen visit http://localhost:8787 to see the JSON response.
- NewsAPI Free: 1000 requests/month, 30/day
- Cloudflare Workers Free: 100,000 requests/day
- Caching: Responses cached for 5 minutes to reduce API calls
If you don't want to use NewsAPI, the worker includes fallback RSS parsing. You can also integrate with:
- Guardian API (free, higher limits)
- NY Times API (free tier available)
- RSS feeds (no API key needed)
- Reddit API (for trending topics)
View worker logs and analytics in the Cloudflare dashboard under Workers & Pages.