A Cloudflare Worker that proxies Reddit JSON API requests, solving CORS and rate limiting issues.
- ✅ CORS headers for browser requests
- ✅ Response caching (5 min TTL)
- ✅ Automatic retries with backoff
- ✅ Proper User-Agent headers
- ✅ URL validation (only reddit.com)
npm install -g wranglerwrangler logincd worker
npm install
npm run deployYour worker will be available at: https://redditify-proxy.<your-subdomain>.workers.dev
GET /thread?url=<reddit_thread_url>
curl "https://redditify-proxy.example.workers.dev/thread?url=https://www.reddit.com/r/PHP/comments/abc123/example"Returns the raw Reddit JSON data with CORS headers.
Edit wrangler.toml to add a custom domain:
routes = [
{ pattern = "reddit-proxy.yourdomain.com", custom_domain = true }
]Edit src/index.ts and change CACHE_TTL (in seconds):
const CACHE_TTL = 300; // 5 minutesCloudflare Workers free tier: 100,000 requests/day
With caching, this handles significant traffic. For higher volume, upgrade to Workers Paid ($5/mo for 10M requests).
After deploying, update your Redditify usage:
<script>
window.REDDITIFY_PROXY_URL = 'https://your-worker.workers.dev';
</script>
<script src="https://unpkg.com/redditify/dist/redditify.min.js"></script>Or set to null to disable proxy (direct fetch, may hit CORS):
<script>
window.REDDITIFY_PROXY_URL = null;
</script>