feat(cfw): add Apps Script + Cloudflare Worker alternative backend#533
Merged
therealaleph merged 1 commit intotherealaleph:mainfrom Apr 30, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in alternative backend for
mode: "apps_script": deployCode.cfw.gs(new GAS variant inassets/apps_script/) plusworker.js(Cloudflare Worker inassets/cloudflare/), and Apps Script becomes a thin auth+forward layer that pushes the outbound fetch to CF's edge. mhrv-rs itself is unchanged — same JSON envelope on the wire, samemode: "apps_script",script_id,auth_key. The only difference is what the deployed Apps Script does after it authenticates.Closes the audit task on the v1.9.x roadmap (#380, #393).
Why
Recurring feedback (most recently in the Persian community) reports that the GAS+CFW combination feels noticeably faster than plain GAS for browsing and chat-style workloads. This PR ports the pattern from denuitt1/mhr-cfw into our deploy assets, hardened, with honest docs about what it does and doesn't deliver.
What ships
assets/cloudflare/worker.js— Cloudflare Worker exit. Hardened over upstream:AUTH_KEYcheck (upstream omits it → open relay if URL leaks).AUTH_KEYstill equals the placeholder.x-relay-hoploop guard + self-host fetch block.Code.gs/UrlFetchApp permissiveness instead of throwing.SKIP_HEADERSparity withCode.gs/Code.cfw.gs(priority,teincluded).Promise.alloverreq.q, per-item{e}slots on partial failure, soft capMAX_BATCH_SIZE = 40paired withWORKER_BATCH_CHUNKon the GAS side.assets/apps_script/Code.cfw.gs— thin GAS relay that forwards to the Worker. Inherits decoy-on-bad-auth +DIAGNOSTIC_MODEfromCode.gs, fail-closes on placeholderAUTH_KEY/WORKER_URL, wrapsUrlFetchApp.fetchin try/catch so network-level Worker failures surface as{e: "worker unreachable: …"}instead of the decoy HTML. Batch path chunks at 40 URLs and dispatches viafetchAll(one quota per chunk, not per URL).assets/cloudflare/README.md+README.fa.md— setup guide, three-matching-AUTH_KEYs security model, trade-off table, full-mode incompatibility section.assets/apps_script/README.md— restructured to clarify which.gsfiles are unmodified upstream (Code.gs), maintained in this repo (CodeFull.gs), or derivative (Code.cfw.gs).README.md— alternative-backend callout in both English and Persian setup guides.Honest limitations (called out prominently in docs)
UrlFetchAppdaily-count relief. mhrv-rs's HTTP-relay path (RelayRequestinsrc/domain_fronter.rs) is single-shape only — it never emitsq: [...]. The batch-aware path on the GAS+Worker side is wired and ready (ceil(N / 40)per N-URL batch) but unreachable from any shipping client. Latency win is real on day one; quota win materialises only if/when a batching client lands. The infrastructure costs nothing to leave in place.mode: "full". Only the HTTP-relay path (modes 1 + 2 inCodeFull.gs) is ported; raw-TCP / UDP tunnel ops (modes 3 + 4) needed for Android full-mode coverage of WhatsApp, Telegram, messengers etc. are not. Won't help that workload.Code.gsfor YouTube-heavy use.Rust client changes
None. Pure GAS/Worker + docs addition. Existing config routes through the new deployment without modification.
Credits
Pattern from denuitt1/mhr-cfw (upstream
mhr-cfwWorker + GAS forwarder design). This port adds theAUTH_KEYcheck, decoy treatment, fail-closed sentinels, exception handling, batch chunking, and the trade-off-honest docs.