Cloudflare

Francesco Ciannavei

Cloudflare

I use Cloudflare as everyday infrastructure: an image CDN I wrote on Workers and R2, a Zero Trust tunnel that brings my home backends online, Turnstile on the contact form, Workers for the frontend, and domains on Cloudflare DNS.

Workers: the frontend at the edge

This site's frontend is Astro and, thanks to the dedicated adapter, runs directly on Cloudflare Workers: pages are generated and served from the edge location closest to the user. The edge-first approach has no perceivable cold start and scales on its own.

An image CDN on Workers and R2

The CDN that serves this site's images is a Cloudflare Worker I wrote in TypeScript. When a request comes in, it checks whether an optimised version is already in the R2 bucket: if it is, it serves it from the cache; if not, it fetches the image from the origin, resizes it and converts it to a lighter format, then stores it in R2.

The conversion follows the browser's Accept header: AVIF when it's supported, otherwise WebP. AVIF encoding is memory-hungry, so above 5 million pixels the Worker falls back to WebP to stay within the 128 MB Cloudflare gives a Worker; if anything fails, it serves the original image. Dimensions and quality come from the w, h and quality parameters, rounded to fixed steps so the cache doesn't fill up with near-identical variants, and every response carries an X-Cache header. The repository is public, with documentation and a button to deploy it to your own account.

Zero Trust: home backends online without exposing an IP

My backends run on home servers, but I never expose a public IP. A Cloudflare Zero Trust tunnel reaches the Laravel CMS API and publishes my applications online, keeping all the traffic flowing through Cloudflare: the data stays on my own servers and behind Cloudflare's protection.

Turnstile on the contact form

This site's contact form is protected with Cloudflare Turnstile, an alternative to traditional CAPTCHAs that usually asks the user for nothing. The token is verified server-side, in the Laravel API, with the same check as the PHP guide I wrote.

DNS

All my domains are managed on Cloudflare DNS, in front of the services above.

Rating
8/10

Where i've used it: