# OnlyClans on Cloudflare (necropsied.com/onlyclans)

The Monstie site is static. OnlyClans runs as a **Cloudflare Pages Function** (Worker) for the API, with static SPA files under `onlyclans/`.

## What was added

| Path | Role |
|------|------|
| `onlyclans/` | Static UI (`index.html`, JS, CSS) |
| `onlyclans/cf/` | KV data layer + crypto for Workers |
| `functions/onlyclans/api/[[path]].js` | API + Discord OAuth at `/onlyclans/api/*` |

## Cloudflare Pages setup

1. Deploy the **monstie** repo as a Cloudflare Pages project (if not already).
2. **Create a KV namespace** named e.g. `onlyclans-data`.
3. Pages project → **Settings → Functions → KV namespace bindings**  
   - Variable name: `ONLYCLANS_KV`  
   - Namespace: your KV  
4. **Settings → Environment variables** (Production):

| Name | Value |
|------|--------|
| `SESSION_SECRET` | long random secret (32+ chars) |
| `DISCORD_CLIENT_ID` | from Discord Developer Portal |
| `DISCORD_CLIENT_SECRET` | from Discord |
| `APP_URL` | `https://www.necropsied.com/onlyclans` |
| `SITE_OWNER_DISCORD_IDS` | `969728138131177522` |

5. Discord OAuth2 → Redirects → add:

```text
https://www.necropsied.com/onlyclans/api/auth/discord/callback
```

6. Redeploy Pages.

## Local Node (optional)

Still works without Cloudflare:

```bash
cd onlyclans
npm install
# BASE_PATH= APP_URL=http://127.0.0.1:8765
npm start
```

## After deploy

Open https://www.necropsied.com/onlyclans/  
API health: https://www.necropsied.com/onlyclans/api/health  

Static HTML alone cannot run Discord OAuth secrets or shared data — the Function + KV is required for login and listings.
