cloudflare/WASM-PROXY.md
BentoPDF uses a Cloudflare Worker to proxy WASM library requests, bypassing CORS restrictions when loading AGPL-licensed components (PyMuPDF, Ghostscript, CoherentPDF) from external sources.
cd cloudflare
npx wrangler login
npx wrangler deploy -c wasm-wrangler.toml
Set environment secrets with the base URLs for your WASM files:
# Option A: Interactive prompts
npx wrangler secret put PYMUPDF_SOURCE -c wasm-wrangler.toml
npx wrangler secret put GS_SOURCE -c wasm-wrangler.toml
npx wrangler secret put CPDF_SOURCE -c wasm-wrangler.toml
# Option B: Set via Cloudflare Dashboard
# Go to Workers & Pages > bentopdf-wasm-proxy > Settings > Variables
Recommended Source URLs:
https://cdn.jsdelivr.net/npm/@bentopdf/[email protected]/https://cdn.jsdelivr.net/npm/@bentopdf/gs-wasm/assets/https://cdn.jsdelivr.net/npm/coherentpdf/dist/Note: You can use your own hosted WASM files instead of the recommended URLs. Just ensure your files match the expected directory structure and file names that BentoPDF expects for each module.
Option A: Environment variables (recommended — zero-config for users)
Set these in .env.production or pass as Docker build args:
VITE_WASM_PYMUPDF_URL=https://bentopdf-wasm-proxy.<your-subdomain>.workers.dev/pymupdf/
VITE_WASM_GS_URL=https://bentopdf-wasm-proxy.<your-subdomain>.workers.dev/gs/
VITE_WASM_CPDF_URL=https://bentopdf-wasm-proxy.<your-subdomain>.workers.dev/cpdf/
Option B: Manual per-user configuration
In BentoPDF's Advanced Settings (wasm-settings.html), enter:
| Module | URL |
|---|---|
| PyMuPDF | https://bentopdf-wasm-proxy.<your-subdomain>.workers.dev/pymupdf/ |
| Ghostscript | https://bentopdf-wasm-proxy.<your-subdomain>.workers.dev/gs/ |
| CoherentPDF | https://bentopdf-wasm-proxy.<your-subdomain>.workers.dev/cpdf/ |
To use a custom domain like wasm.bentopdf.com:
wasm-wrangler.toml:routes = [
{ pattern = "wasm.bentopdf.com/*", zone_name = "bentopdf.com" }
]
Add DNS record in Cloudflare:
Redeploy:
npx wrangler deploy -c wasm-wrangler.toml
ALLOWED_ORIGINS in wasm-proxy-worker.js to include your domain| Endpoint | Description |
|---|---|
/ | Health check, shows configured modules |
/pymupdf/* | PyMuPDF WASM files |
/gs/* | Ghostscript WASM files |
/cpdf/* | CoherentPDF files |