diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e164e1..923f23d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # Changelog +## v2.3.1 +### Cloudflare Worker Edition — Streaming Bypasses Cloudflare + +#### New: `worker.js` (Cloudflare Worker) +- Full API running on Cloudflare's edge network +- **Streaming endpoints work** — edge-to-edge requests bypass bot detection +- Zero cold starts, 100K free requests/day +- No npm dependencies (native `fetch` + `DecompressionStream`) +- 15 endpoints: search, trending, info, episodes, watch, genres, random + +#### Why Workers Work +``` +Vercel (datacenter) → miruro.to → Cloudflare blocks ❌ +Worker (edge) → miruro.to → Cloudflare trusts itself ✅ +``` + +#### Deploy +```bash +npm install -g wrangler +wrangler login +wrangler deploy worker.js --name miruroapi +``` + +#### Files Changed +- `worker.js` — Cloudflare Worker implementation (885 lines) +- `README.md` — Added Worker deployment section, updated troubleshooting +- `docs/architecture.md` — Added Worker architecture section + +--- + ## v2.3.0 ### Self-Healing Fallback System — Auto-Recovery from Cloudflare Blocks diff --git a/README.md b/README.md index c1c8c88..6d7e4e5 100644 --- a/README.md +++ b/README.md @@ -1414,6 +1414,32 @@ docker build -t miruroapi . docker run -p 3000:3000 miruroapi ``` +### ⚡ Cloudflare Worker (Streaming Works!) + +> **Streaming endpoints work on Workers** — requests to Miruro bypass Cloudflare bot detection because Workers run on Cloudflare's edge network (edge-to-edge traffic is trusted). + +```bash +# Install wrangler CLI +npm install -g wrangler + +# Login to Cloudflare +wrangler login + +# Deploy +wrangler deploy worker.js --name miruroapi +``` + +Your API is live at: `https://miruroapi.YOUR_SUBDOMAIN.workers.dev` + +| Feature | Vercel | Cloudflare Worker | +|---------|--------|-------------------| +| Streaming (pipe) | Blocked (403) | Works | +| Cold starts | ~500ms | Zero | +| Free tier | Unlimited | 100K req/day | +| npm deps | Yes | No (native fetch) | + +> See `worker.js` for the full Worker implementation with 15 endpoints. + --- ## 📜 Available Scripts @@ -1492,7 +1518,27 @@ Cloudflare detects: - Missing browser fingerprint headers - Non-residential traffic patterns -#### Fix 1: ScraperAPI (Easiest — Free Tier) +#### Fix 1: Cloudflare Worker (Best — Free, Works!) + +Workers run on Cloudflare's edge network. Edge-to-edge requests are trusted — no bot detection. + +```bash +# 1. Install wrangler +npm install -g wrangler + +# 2. Login +wrangler login + +# 3. Deploy +wrangler deploy worker.js --name miruroapi + +# 4. Your streaming now works at: +# https://miruroapi.YOUR_SUBDOMAIN.workers.dev/api/episodes/20 +``` + +**Cost:** Free (100K requests/day). No API key needed. + +#### Fix 2: ScraperAPI (Paid — $49/month) ScraperAPI proxies your requests through residential IPs, bypassing Cloudflare. @@ -1505,7 +1551,7 @@ SCRAPER_API_KEY=your_api_key_here **Cost:** $49/month (premium plan required for protected domains like Miruro). -#### Fix 2: FlareSolverr (Self-Hosted — Unlimited) +#### Fix 3: FlareSolverr (Self-Hosted — Unlimited) FlareSolverr runs a headless browser that bypasses Cloudflare automatically. @@ -1524,7 +1570,7 @@ FLARESOLVERR_URL=http://your-server-ip:8191 - Public IP address - Docker installed -#### Fix 3: Self-Host the Entire API +#### Fix 4: Self-Host the Entire API If you run the API on your own VPS (not Vercel), requests come from your residential/datacenter IP which may not be blocked. diff --git a/docs/architecture.md b/docs/architecture.md index 128ed47..45e8996 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -5,6 +5,7 @@ ``` MiruroAPI/ ├── server.js # Express entry point, port 3000 +├── worker.js # Cloudflare Worker edition (edge runtime) ├── package.json # name: "miruro-api" ├── vercel.json # Routes /api/* and /* to server.js ├── Dockerfile # Docker support (node:20-alpine) @@ -198,3 +199,52 @@ Error responses: | axios | ^1.8.0 | HTTP requests | | cors | ^2.8.5 | CORS headers | | dotenv | ^16.4.0 | Environment variables | + +## Cloudflare Worker Architecture (v2.3.1) + +The Worker edition (`worker.js`) runs the same API on Cloudflare's edge network. Key difference: **streaming endpoints work** because edge-to-edge requests bypass Cloudflare bot detection. + +### Why Workers Work + +``` +Vercel (datacenter IP) → miruro.to → Cloudflare WAF → 403 Blocked +Cloudflare Worker (edge) → miruro.to → Cloudflare internal network → 200 OK +``` + +### Worker Runtime Differences + +| Feature | Express (Node.js) | Cloudflare Worker | +|---------|-------------------|-------------------| +| HTTP client | axios | native fetch | +| Decompression | zlib (Node.js) | DecompressionStream (Web API) | +| Caching | in-memory Map | Workers KV (optional) | +| npm packages | Yes | No (bundle only) | +| Cold starts | ~500ms | Zero | +| CPU limit | None | 10ms (free) / 30s (paid) | + +### Worker Endpoints (15) + +| Endpoint | Description | +|----------|-------------| +| `GET /api/health` | System health check | +| `GET /api/search?query=` | Full-text anime search | +| `GET /api/suggestions?query=` | Autocomplete suggestions | +| `GET /api/filter?genre=` | Advanced filter | +| `GET /api/trending` | Trending anime | +| `GET /api/popular` | Most popular | +| `GET /api/top` | Top scored | +| `GET /api/random` | Random anime | +| `GET /api/info/:id` | Full anime info | +| `GET /api/anime/:id/characters` | Characters + voice actors | +| `GET /api/anime/:id/relations` | Related anime | +| `GET /api/genres` | All genres | +| `GET /api/episodes/:id` | Episode list (pipe) | +| `GET /api/watch/:provider/:anilistId/:category/:slug` | Streaming sources (pipe) | + +### Deploy + +```bash +npm install -g wrangler +wrangler login +wrangler deploy worker.js --name miruroapi +```