Domains:
This repository contains the full source and CI/CD configuration for the PreAngel Edge Proxy, a Cloudflare Worker that transparently serves GitHub Pages content to multiple domains with domain-specific branding and edge caching.
- Cloudflare account with both domains (
pre-angel.com,preangel.ai) in DNS. - Wrangler CLI installed.
- Node.js ≥ 18 and Git installed.
# 1. Clone this repo
git clone https://github.com/huan/preangel-proxy.git
cd preangel-proxy
# 2. Authenticate with Cloudflare
wrangler login
# 3. Deploy the Worker
wrangler deploy
# 4. (Optional) Tail logs in real time
wrangler tail preangel-proxyThat’s it! Your Worker will automatically serve both domains through Cloudflare’s global CDN.
The goal of this project is to host the same GitHub Pages site under two domains — pre-angel.com and preangel.ai — while keeping the browser URL unchanged for branding consistency.
We achieve this using a Cloudflare Worker reverse proxy with global caching and HTML rewriting.
- Transparent proxy — serves
huan.github.iocontent without redirects. - Multi-domain branding — custom titles, meta descriptions, and canonical tags per domain.
- Edge caching — leverages Cloudflare’s global CDN for ultra-fast delivery.
- SEO-safe canonical links — prevent duplicate-content penalties.
- CI/CD via GitHub — automatic deployment on
git push.
Browser → Cloudflare Edge → Worker (preangel-proxy) → GitHub Pages (huan.github.io)
- The Worker runs at Cloudflare’s edge (310+ PoPs worldwide).
- It rewrites incoming requests, fetches from GitHub Pages, injects domain-specific HTML, and caches responses at the edge.
- Both
pre-angel.comandpreangel.aimap to the same Worker.
The Worker uses Cloudflare’s streaming HTMLRewriter API to modify the HTML <head> for each domain:
.on("title", e => e.setInnerContent(siteMeta.title))
.on("head", e => e.append(`
<meta name="theme-color" content="${siteMeta.color}">
<meta name="description" content="${siteMeta.desc}">
<link rel="canonical" href="https://${host}${path}">
`, { html: true }))Each response is cached using caches.default for 10 minutes (max-age=600), plus stale-while-revalidate=60 for smooth background refresh.
ctx.waitUntil(cache.put(request, response.clone()))This means Cloudflare will serve subsequent requests directly from the nearest data center.
-
Local Setup
npm install -g wrangler wrangler login wrangler init --from-dash preangel-proxy
-
Connect to GitHub
- Push this folder to GitHub:
huan/preangel-proxy. - In Cloudflare → Workers → preangel-proxy → Connect to GitHub.
- Select branch
mainfor automatic deployments.
- Push this folder to GitHub:
-
Custom Domains
- Add both
pre-angel.comandpreangel.aiunder Triggers → Custom Domains.
- Add both
-
Deploy manually (optional)
wrangler deploy
-
Real-time logs
wrangler tail preangel-proxy
preangel-proxy/
├─ src/
│ └─ index.js # Worker code (HTMLRewriter proxy)
├─ wrangler.toml # Cloudflare config (routes + domains)
├─ package.json # Optional npm deps
├─ .github/workflows/ # GitHub Actions CI/CD
│ └─ deploy.yml
└─ README.md # (this file)
name = "preangel-proxy"
main = "src/index.js"
compatibility_date = "2025-11-10"
routes = [
{ pattern = "pre-angel.com/*", custom_domain = true },
{ pattern = "preangel.ai/*", custom_domain = true }
]Cloudflare provides analytics across layers:
- Workers Analytics: latency, requests, subrequests, CPU time
- Cache Analytics: edge cache hit ratios
- Zone Analytics: traffic and threats per domain
wrangler tail preangel-proxySELECT
host,
COUNT(*) AS requests,
AVG(http.request_latency_ms) AS avg_latency,
SUM(CASE WHEN cache.status='hit' THEN 1 ELSE 0 END) / COUNT(*) AS hit_ratio
FROM worker_requests
WHERE datetime > NOW() - INTERVAL 1 DAY
GROUP BY host;- Keep branding consistent across multiple domains.
- Avoid redirects — preserve the original host in the URL.
- Optimize latency and SEO simultaneously.
- Make everything reproducible via GitHub CI/CD.
- Add per-domain analytics dashboards (Grafana template)
- Integrate with Cloudflare KV or D1 for dynamic content
- Use durable objects for cross-domain session persistence
- Edge A/B testing with personalized meta injection
Built by Huan Li (@huan) under PreAngel LLC, with ❤️ for open web infrastructure.
"Keep your domains elegant, your cache hot, and your latency low." — PreAngel