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 loginReddit blocks unauthenticated JSON API access from datacenter IPs (including Cloudflare Workers), so the worker authenticates via Reddit's application-only OAuth flow.
- Go to https://www.reddit.com/prefs/apps and click "create another app..."
- Choose type script, any name, and
http://localhostas redirect URI - Note the client ID (under the app name) and the secret
- Set them as worker secrets:
cd worker
wrangler secret put REDDIT_CLIENT_ID
wrangler secret put REDDIT_CLIENT_SECRETThe free OAuth tier allows 100 queries/minute per client — comfortable with the worker's 5-minute response cache.
cd 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>