# Deploy DAAM on Cloudflare Workers

The site is a Worker (`main`) plus static assets (`public/`, fonts, images, `robots.txt`, `security.txt`). There is no database and no `DATABASE_URL`.

## 1. One-time account setup

1. Node 20+ and this project’s files.
2. A Cloudflare account. If `daam.io` is not already on Cloudflare, add the zone (free plan is enough) and switch the nameservers.
3. In a terminal at the project root:

```bash
npm install
npx wrangler login
npx wrangler whoami
```

The browser window must finish authorizing Wrangler.

## 2. Fill `wrangler.jsonc`

| Field | What to put |
| --- | --- |
| `name` | Worker name. Default `daam`. Must be unique in the account. |
| `account_id` | Optional. 32-character id from **Workers & Pages → Overview**. Uncomment the line and paste it if Wrangler asks which account. |
| `compatibility_date` | Keep `2026-08-27` or today’s date (`YYYY-MM-DD`). |
| `compatibility_flags` | Keep `nodejs_compat`. Do not remove it. |
| `main` | Keep `.output/server/index.mjs`. That file exists only **after** `cf:build`. |
| `assets.directory` | Keep `.output/public`. |
| `assets.binding` | Keep `ASSETS`. The SSR worker reads static files through this binding. |
| `no_bundle` | Keep `true`. Nitro already bundled the worker; Wrangler must not re-bundle. |
| `routes` | Leave commented until the first deploy succeeds. |

Do not add KV, D1, R2, or vars unless you later add a feature that needs them.

## 3. Build the Worker

```bash
npm run cf:build
```

Confirm these exist:

- `.output/server/index.mjs`
- `.output/public/robots.txt`
- `.output/public/.well-known/security.txt`
- `.output/public/_headers`

## 4. First deploy (workers.dev)

```bash
npm run cf:deploy
```

That is `cf:build` + `wrangler deploy`. Wrangler prints a URL like:

`https://daam.<your-subdomain>.workers.dev`

Open it. You should see the field manual, not a Wrangler error page.

Local check before shipping:

```bash
npm run cf:preview
```

## 5. Attach `daam.io`

**Dashboard (safest first time)**

1. Cloudflare → **Workers & Pages** → **daam** → **Settings** → **Domains & Routes**.
2. **Add** → Custom domain → `daam.io`.
3. Repeat for `www.daam.io` if you use www.
4. Wait until the domain status is **Active**. SSL is issued automatically when the zone is on Cloudflare.

**Or Wrangler**

In `wrangler.jsonc` uncomment:

```jsonc
"routes": [
  { "pattern": "daam.io", "custom_domain": true },
  { "pattern": "www.daam.io", "custom_domain": true }
]
```

Then:

```bash
npm run cf:deploy
```

The zone `daam.io` must already belong to the same account. If Wrangler errors on the custom domain, use the dashboard path above.

## 6. DNS and HTTPS

In the `daam.io` zone:

| Type | Name | Target | Proxy |
| --- | --- | --- | --- |
| created by custom-domain attach | `@` and `www` | the Worker | Proxied (orange cloud) |

Do not point the apex at a third-party IP. SSL/TLS mode: **Full (strict)**.

Optional www → apex: **Rules → Redirect Rules** (or Bulk Redirects):

- `https://www.daam.io/*` → `https://daam.io/${1}` (301)

## 7. Protections (dashboard)

None of these require Wrangler fields:

- **WAF** → managed ruleset on.
- **Bot Fight Mode** on (or Super Bot Fight if paid).
- **Security → Settings** → “I’m Under Attack” only if you are actually under attack.
- **Scrape Shield / Email Obfuscation** off for this site (contact is a `mailto:` the user opted into).
- **Speed → Caching**: respect `_headers`. Do not cache HTML if you later add cookies; this app has none.

## 8. Checks after go-live

Open:

- `https://daam.io/`
- `https://daam.io/robots.txt`
- `https://daam.io/.well-known/security.txt`
- `https://daam.io/sitemap.xml`

`security.txt` must list `Contact: mailto:contact@daam.io` and `Canonical: https://daam.io/.well-known/security.txt`.

## Commands

| Command | What it does |
| --- | --- |
| `npx wrangler login` | OAuth to your Cloudflare account |
| `npx wrangler whoami` | Confirm the account |
| `npm run cf:build` | Nitro `cloudflare-module` build into `.output/` |
| `npm run cf:preview` | Build, then `wrangler dev` |
| `npm run cf:deploy` | Build, then `wrangler deploy` |
| `npx wrangler deployments list` | Recent versions |
| `npx wrangler rollback` | Revert a bad deploy |

Grok’s **Publish** button still ships a separate Vercel copy. Use Wrangler for `daam.io`.
