All demos / Workers ยท Routes ยท HTMLRewriter

The core concept

Your origin server never
knows a Worker exists.

A Cloudflare Worker intercepts HTTP requests that match a Route pattern (e.g. *shoplegacy.com/*). Your origin receives a perfectly normal request, returns a normal response, and the Worker transforms it on the way back โ€” invisibly.

โœ“

Origin code unchanged

0 lines edited

โœ“

DNS unchanged

same domain, same records

โœ“

Deploy in 10 seconds

one command: wrangler deploy

Request Flow

Browser

sends request

โšก Cloudflare Edge
Route Check
*shoplegacy.com/*
Worker
runs here

Your Origin

unchanged โœ“

Click "See how routes work" to animate

Everything you need โ€” 2 files + 1 command

1
โœ๏ธ Write a Worker

A small TypeScript file. It fetches from your origin, optionally transforms the response, and returns it. Your origin gets a normal HTTP request.

await fetch(request) // calls your origin .then(res => transform(res)) // modify
2
๐Ÿ—บ Add a Route

One line in wrangler.toml tells Cloudflare which URLs this Worker intercepts. Pattern supports wildcards. Multiple routes supported.

pattern = "*shoplegacy.com/*"
3
๐Ÿš€ Deploy

One command. Worker is live globally in ~10 seconds on Cloudflare's 250+ PoPs. Rollback is one command too.

wrangler deploy # done

Total changes to your origin: 0 โ€” Not one line. The Worker is deployed independently on Cloudflare's infrastructure, not on your servers.

Same URL. Two different experiences.

Left: origin only ยท Right: Worker route active (chatbot injected via HTMLRewriter)

Click "See Routes in Action" to load both versions

Other things the same route can do