# Blog backend (optional — needed for a real, shared blog)

Without this, the blog's admin panel (`blog/admin.html`) still works, but it
saves posts to your browser's local storage only — visible to you, on that
one device, not to actual visitors of your site. This Worker gives you a
real, shared backend so posts you publish are visible to everyone.

## Deploy (about 5 minutes, free)

1. Go to https://dash.cloudflare.com → **Workers & Pages** → **Create** → **Worker**.
2. Delete the sample code and paste in the entire contents of `worker.js`.
3. Go to **Settings → Variables → KV Namespace Bindings → Add binding**.
   Create a new KV namespace (e.g. `crawlie-blog`) and bind it to the
   variable name **`BLOG_POSTS`** — this name must match exactly.
4. Go to **Settings → Variables → Environment Variables → Add variable**.
   Name: **`ADMIN_TOKEN`**. Value: any long random string you make up (this
   is your admin password for the blog). Click the option to encrypt it so
   it's stored as a secret.
5. Click **Deploy**. You'll get a URL like `https://crawlie-blog.<you>.workers.dev`.
6. Open `blog/admin.html` on your site, expand **"Connect your blog backend"**,
   paste in that Worker URL and the `ADMIN_TOKEN` you chose, and save.

That's it — posts you create/edit/delete in the admin panel are now stored in
Cloudflare KV and served to every visitor of `blog/index.html`.

## Free tier

Cloudflare Workers KV's free tier (100,000 reads/day, 1,000 writes/day) is far
more than a personal or small business blog needs.

## Security note

The `ADMIN_TOKEN` is a simple shared-secret check, not full user accounts —
treat it like a password. Anyone with the token can create, edit, or delete
posts. Don't share it publicly, and rotate it (create a new one in the
Worker's environment variables) if you ever suspect it's been exposed.
