Cloudflare
The company that sits between your website and its visitors: domains, DNS, HTTPS and protection for free, plus Workers and D1 to run a whole site without renting a server.
01 · Introduction
What Cloudflare is
Cloudflare runs a huge network of servers in hundreds of cities. When someone opens your website, they reach the Cloudflare server nearest to them first, and Cloudflare serves the page or passes the request on.
For a beginner it does two jobs:
- Looks after your domain. It manages your domain's records (DNS: the address book that says where
yourname.compoints), gives you HTTPS for free, and blocks most attacks and bots. - Runs your website. With Workers your site's code runs on Cloudflare's network, so you don't rent a server, and you pay nothing while traffic is small.
Words you will see:
- Workers: where your site's code runs. Each project is one Worker. You get a free address like
name.your-account.workers.dev. - D1: a database (SQLite) on Cloudflare, used by Workers to store users, orders and posts.
- R2: file storage for images and uploads.
- Pages: hosting for static sites. For a site with logins and payments, Workers is the usual choice.
- Wrangler: Cloudflare's command-line tool. Agents use it to create databases and deploy.
02 · When to use it
When to use it
- You want a website without managing a server. Workers + D1 run a full site (pages, sign-in, payments, admin) with nothing to patch or restart.
- You bought a domain and want HTTPS, fast loading worldwide and protection against bots, all free.
- A side project or a first product, where you want to pay nothing until people actually use it.
- Many small sites. Each one is just another Worker on the same account.
It is a weaker fit when your code needs a long-running process, a big traditional database, or heavy computation on every request. Those still belong on a normal server.
03 · Setup
How to set it up
- Create an account at dash.cloudflare.com. It is free and needs only an email.
- Add your domain (optional). Either buy one inside Cloudflare (Domain Registration), or add one you own elsewhere: Cloudflare shows two nameservers, and you replace the old ones at the company where you bought the domain. It usually takes effect within an hour.
- Let your computer deploy for you. Install Node.js, then run
npx wrangler login. A browser page opens; if you are already signed in to Cloudflare, just click Allow.
That is all an agent needs. From then on you can say "deploy this to Cloudflare Workers with a D1 database" and it runs the Wrangler commands itself.
04 · Deployment
Putting a site on Workers
With an agent, deploying is a sentence: "deploy to Cloudflare Workers, use D1". Behind it, the agent:
- creates a D1 database (
wrangler d1 create <name>) and its tables, - builds the site and uploads it (
wrangler deploy), - gives you the
*.workers.devaddress.
To use your own domain: in the Cloudflare dashboard open Workers & Pages → your Worker → Settings → Domains & Routes → Add → Custom Domain, and type the domain. The domain must already be on your Cloudflare account. HTTPS is set up automatically.
Name the D1 database after your domain (mysite.com → mysite) before creating it: a D1 database cannot be renamed later.
05 · How to use it
Day-to-day use
- Updating the site: change the code, then deploy again (or tell the agent "redeploy"). The new version is live in seconds.
- Seeing what happened: Workers & Pages → your Worker → Logs shows errors and requests. Paste an error to your agent to have it fixed.
- Looking at the data: Storage & Databases → D1 lets you browse tables and run SQL in the browser.
- Rolling back: the Worker's Deployments tab lists every version; you can switch back to an earlier one.
- Scheduled jobs: Workers can run on a timer (Cron Triggers), for example a nightly cleanup or a daily report.
06 · Pitfalls
Things to watch out for
- Free limits. The free plan includes 100,000 Worker requests a day and, for D1, 100,000 rows written a day. If writes run out, the site still shows pages but sign-ups and orders fail. When traffic grows, Workers Paid is $5 a month (paid by card) and raises every limit.
- D1 names are permanent. Choose before you create it.
- Secrets are not settings. API keys go in as secrets (
wrangler secret put), never in the publicvarsof the config file. - Upload size. One Worker can be at most a few dozen MB. Big files (videos, many images) belong in R2, not in the code.
- Moving DNS changes email too. When you move a domain to Cloudflare, check that its email records (MX) came along, or mail to that domain stops.
07 · Resources
