Part D. Cloudflare: every setting, in order
Cloudflare’s menus are renamed from time to time. Where a menu name below does not match your screen, search the dashboard for the setting’s name (the bold words) and tell me what you see; do not guess. Anything marked “verify” depends on Cloudflare’s current free-plan limits.
D.1 Check the domain and protect the account
Section titled “D.1 Check the domain and protect the account”- Sign in at dash.cloudflare.com and open the bideward.com site (you registered it on this account on 29 Nov 2026, with auto-renew on). On Overview the status should read Active. If it says Pending, wait a few minutes and refresh; if it still says Pending after an hour, stop and tell me.
- Profile (top right) → Authentication: turn on two-factor authentication with an authenticator app, and download the recovery codes. Store them offline (not in Drive, not in chat).
- Profile → API Tokens: if any token or Global API Key exists that you do not recognise, roll or delete it. Do not create any new token for this migration; the tunnel uses its own token.
- DNS → Records: check that no record named app or api exists yet. The tunnel creates them in D.3. Do not point app or api at the Lightsail IP; the server must never be reachable by IP.
D.2 Zero Trust (needed for the Tunnel and for Access)
Section titled “D.2 Zero Trust (needed for the Tunnel and for Access)”- In the dashboard sidebar open Zero Trust. The first time, it asks for a team name (for example bideward); it becomes the login address of the Access page. Choose the Free plan. Zero Trust Free is $0 for up to 50 users. It may ask for a payment method to activate the plan; verify what it asks before entering anything, and stop and tell me if the price shown is not $0.
- Settings → Authentication: the One-time PIN login method is on by default. Keep it; it emails a code to the address you allow in D.7.
D.3 Create the tunnel and the hostname
Section titled “D.3 Create the tunnel and the hostname”- Zero Trust → Networks → Tunnels (on newer screens: Networks → Connectors) → Create a tunnel → choose Cloudflared.
- Name: bideward-lightsail. Save.
- Choose the environment Debian, 64-bit. The page shows an install command with a long token. Do not run that command and do not paste the token anywhere except the file in F.4. Copy only the token (the long text after –token), and keep the page open.
- Public hostname tab → Add a public hostname twice. First: Subdomain app; Domain bideward.com; Path empty; Service Type HTTP; URL 127.0.0.1:8080. Second: Subdomain api; Domain bideward.com; Path empty; Service Type HTTP; URL 127.0.0.1:8080. Save each. Cloudflare creates a proxied DNS record for each by itself. Both names go to the same hub; the hub answers each route only on its own hostname (E.5): dashboard and owner routes on bideward, bot, loader and feed routes on bideward-api.
- Do not add any other hostname now. The research service stays private (see Part F); the hub forwards /research to it inside the server. admin.bideward.com is added later (Part Q), when the owner pages exist.
- Back in DNS → Records, confirm two new records: app and api, type CNAME, target <id>.cfargotunnel.com, Proxied (orange cloud). Both must stay proxied.
Until F.4 is done the tunnel shows Inactive or Down. That is expected.
D.4 SSL/TLS settings
Section titled “D.4 SSL/TLS settings”| Setting | Where | Value | Why |
|---|---|---|---|
| Encryption mode | SSL/TLS → Overview | Full (strict) | The tunnel already encrypts the path to the server; strict mode refuses any plain link if an origin is ever added. |
| Always Use HTTPS | SSL/TLS → Edge Certificates | On | Loaders and bots must never talk plain HTTP. |
| Minimum TLS version | SSL/TLS → Edge Certificates | 1.2 | Blocks old, weak clients. |
| TLS 1.3 | SSL/TLS → Edge Certificates | On | Faster handshakes. |
| Automatic HTTPS Rewrites | SSL/TLS → Edge Certificates | On | Harmless. |
| HSTS | SSL/TLS → Edge Certificates | Leave Off for now | HSTS on a whole domain can apply to every name under bideward.com for a long time; turn it on later, only after every name on bideward.com is served over https. |
| Universal certificate | SSL/TLS → Edge Certificates | Nothing to do | It covers bideward.com and one level of subdomain, so app.bideward.com and api.bideward.com are covered. A name like api.app.bideward.com would not be; do not use one. |
D.5 Network settings
Section titled “D.5 Network settings”- Network → WebSockets: On (the default). The bots’ live feed uses it.
- Network → HTTP/3 (QUIC): On is fine. gRPC: not needed.
- Caching → Cache Rules → Create rule: name “bideward no cache”; when Hostname is in app.bideward.com, api.bideward.com; then Bypass cache. The receiver’s answers are live data and must never be cached at the edge.
- Rules → Page Rules or Configuration Rules: nothing is needed. Do not enable Rocket Loader, Auto Minify, Mirage or Polish for this hostname; they rewrite pages and break scripts. If Speed → Optimization shows any of them On for the zone, add a Configuration Rule for the two Bideward hostnames that turns them Off.
D.6 WAF: rules that stop junk before it reaches the server
Section titled “D.6 WAF: rules that stop junk before it reaches the server”The server only has to answer bots, loaders, the dashboard and the research page. Everything else is dropped at Cloudflare. Create these in Security → WAF → Custom rules, in this order. Verify the free plan’s number of custom rules (it has been 5); the three below fit.
| Rule name | When the request matches | Action | Notes |
|---|---|---|---|
| bideward block bad methods | Hostname is app.bideward.com or api.bideward.com and method is not one of GET, POST, OPTIONS, HEAD | Block | The receiver uses only these four. |
| bideward ingest needs key | Hostname is api.bideward.com and method is POST and path is one of the ingestion paths and the request has no X-Titan-Key header | Block | The exact ingestion paths and the exact header name are read from worker.js when the adapter is built (step E1) and written here before this rule is switched on. Until then leave the rule disabled. |
| bideward block scanners | Hostname is app.bideward.com or api.bideward.com and path contains /.env or /.git or /wp- or /phpmyadmin or /admin.php | Block | Stops the usual scanner traffic. |
- For each rule: Create rule → give it the name → build the expression with the dropdowns (or Edit expression) → choose the action → Deploy. Save it as a draft first if you want to review.
- Never use Managed Challenge on ingestion paths. A bot or userscript cannot solve a challenge and would stop sending.
- Security → Settings: Security Level Medium; Browser Integrity Check On for the dashboard, but see D.8: it can reject userscript calls with an unusual user agent, so test it with a bot before leaving it On.
D.7 Rate limiting and Access
Section titled “D.7 Rate limiting and Access”Rate limit (login and control endpoints). Security → WAF → Rate limiting rules → Create rule. Name “bideward login limit”. When path is one of the sign-in and control endpoints (the exact list comes from worker.js in step E1) and Hostname is app.bideward.com. Count by IP. Free plan: one rule, a 10-second window; verify. Suggested limit: 10 requests per 10 seconds, action Block, duration 10 seconds (the longest the free plan allows; verify). The receiver keeps its own 5-tries / 15-minutes lock; this only slows floods.
Access (the Research page and, after testing, the Admin pages).
- Zero Trust → Access → Applications → Add an application → Self-hosted.
- Name: Bideward research. Session duration 24 hours. Application domain: app.bideward.com, path research (the app then covers /research and everything under it).
- Policy: name “owner only”, action Allow, Include: Emails → your own email address only. Save.
- Login method: One-time PIN. Save the application.
- Test in a private browser window: opening app.bideward.com/research must show the Cloudflare Access email screen first, then your normal dashboard sign-in. The bots and loaders never use /research, so they are not affected.
- The owner’s admin pages get the same protection later on admin.bideward.com (Part Q), after the migration is stable. They are not on the bots’ hostname, so a mistake there cannot lock the loaders out.
- The hub also checks the Cf-Access-Jwt-Assertion header on /research (team name and application audience from the Access application’s Overview page) so that nobody can skip Access even if a rule is changed by mistake. This check is built in the adapter (part E) and kept off until the application exists.
D.8 Bot Fight Mode and Browser Integrity Check
Section titled “D.8 Bot Fight Mode and Browser Integrity Check”- Security → Bots → Bot Fight Mode. On the free plan it cannot be skipped by a rule for one path. It can block the Tampermonkey feed, the loader’s requests from a betting site, or Node tools with no browser headers.
- Plan: leave it Off first. Run the one-to-three-bot validation (Part I). Then switch it On, repeat the validation, and read Security → Events for any Bot Fight Mode block. If a bot request is blocked, switch it Off again and tell me; the key-header rule in D.6 then does the protection.
- Do the same test for Browser Integrity Check (Security → Settings).
D.9 Alerts when the tunnel stops
Section titled “D.9 Alerts when the tunnel stops”- Notifications (account level) → Add → choose the Cloudflare Tunnel health alert (name may read Tunnel Health Alert). Choose all tunnels or bideward-lightsail. Delivery: your email. Save. Verify availability on the free plan.
- Add also the HTTP DDoS attack alert if it is offered, delivery email.
- The server also reports its own health to Telegram (Part K); the Cloudflare email is the second, independent watcher.
D.10 What to leave alone
Section titled “D.10 What to leave alone”| Item | Rule |
|---|---|
| The old Worker (titan-stats on workers.dev) | Do not delete it until Part L. It holds the old data and is the rollback of last resort. |
| Durable Object database | Never delete it before the data has been exported and verified (Part G). |
| Cloudflare API tokens | None needed. If one is ever created, it is scoped to one zone and one permission, with an expiry date, never the Global API Key. |
| Origin IP | There is none to hide: the server has no inbound port at all. Never publish the Lightsail address anywhere. |
| Free-plan limits | Re-read the current limits for custom rules, rate limiting and Zero Trust on the day you set them; they change. |
D.11 The “back shortly” page and the status page (free plan)
Section titled “D.11 The “back shortly” page and the status page (free plan)”EXPLAIN — why: if the tunnel or the server is down, Cloudflare shows its own error page (1033 or 502), which looks unprofessional. Custom error pages are a paid-plan feature, so on the free plan a small Worker does the job.
How it behaves:
- A Worker route on app.bideward.com for dashboard page loads only. It is not on api.bideward.com, so bot traffic never reaches it.
- It passes each request on to the hub. If the hub answers, the answer goes back unchanged. If Cloudflare reports the origin as unreachable (status 530, 502, 503 or 504), it returns our own page: “Bideward is briefly unavailable. We are working on it. This page refreshes by itself.”, with HTTP status 503 and a Retry-After header.
- It stores nothing, so it cannot meet the Durable Object limit that caused this migration. The free plan allows 100,000 Worker requests a day; dashboard page loads are a tiny fraction of that.
- Bots and loaders on api.bideward.com get a failure they already treat as “receiver down” and retry. When the hub is up but in maintenance mode it answers 503 with Retry-After and a small JSON body, so loaders back off cleanly.
- A status page (a static page on Cloudflare Pages, for example status.bideward.com) shows the last result of the external monitor from Part K, so people can check even when Bideward itself is down. It is free and needs no server.
Built (branch 3): one small file in the repository (deploy/downpage-worker.js) and its own deploy file (deploy/wrangler-downpage.toml), a separate Worker named bideward-downpage from the old receiver Worker, with no secrets, no storage and no Durable Object. It replaces only a page load (GET or HEAD that accepts HTML) that comes back 530, 502, 503 or 504, or that cannot reach the hub; API calls, WebSockets, other methods and every other status pass through untouched, so the hub’s own JSON maintenance answer is never replaced for an API call. Deploy it by hand from the repository root once the domain is in Cloudflare (Part D): npx wrangler deploy -c deploy/wrangler-downpage.toml. Its behaviour is tested (tests/deploy.mjs, 13 checks) with test requests; whether Cloudflare hands a Worker the tunnel error as an ordinary response is checked live in I.3.
VERIFY: the tunnel-off test in I.3 must show our page, not Cloudflare’s. I have not yet confirmed that the Worker sees the tunnel error as an ordinary response; if it does not, we fall back to a plain static page and I will tell you.
Cloudflare’s paid plans would replace the Worker with a built-in custom error page. That option is in the backlog for when money allows.
← Previous: Part C. The complete database design · Guide index · Next: Part E. The Node adapter: what will be built →