Skip to content

Commit 183950a

Browse files
committed
docs: expand Cloudflare adapter guide with Git workflow, build flow, and R2 update notes
1 parent 10de82a commit 183950a

3 files changed

Lines changed: 503 additions & 12 deletions

File tree

docs/cli/create-statikapi.mdx

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,32 @@ npx create-statikapi
2828

2929
You will be prompted for:
3030

31-
- **Template**: `basic`, `dynamic`, or `remote-data`
31+
- **Template**:
32+
- `basic` — single endpoint starter
33+
- `dynamic` — dynamic + catch-all routes examples
34+
- `remote-data` — build-time fetch examples
35+
- `cloudflare-adapter` — Cloudflare Worker + R2 + KV with build webhook
3236
- **Package manager** and whether to install now
33-
- Optional ESLint, TS, directories, and deploy presets
37+
- Optional ESLint, TS, directories, and deploy presets
38+
_(For the Cloudflare adapter template, ESLint/TS are effectively skipped; you get a JS Worker-focused boilerplate.)_
3439

35-
> **Note:** The **source** (`src-api/`) and **output** (`api-out/`) directories are defaults. You can **customize** these during scaffolding or later in your [Configuration](../config).
40+
> **Note:** The **source** (`src-api/`) and **output** (`api-out/`) directories are defaults for the core templates.
41+
> You can **customize** these during scaffolding or later in your [Configuration](../config).
42+
> For the Cloudflare adapter template, `src-api/` is still the default, but the JSON is pushed to **R2** instead of a local `api-out/` for hosting.
3643
3744
---
3845

3946
## Flags
4047

41-
- `--template basic|dynamic|remote-data`
42-
- `--yes, -y` — accept defaults (noninteractive)
48+
- `--template basic|dynamic|remote-data|cloudflare-adapter`
49+
- `--yes, -y` — accept defaults (non-interactive)
4350
- `--no-install`
4451
- `--no-gitignore`
4552
- `--package-manager pnpm|npm|yarn`
4653
- `--src-dir <dir>` (default `src-api`, configurable)
47-
- `--out-dir <dir>` (default `api-out`, configurable)
48-
- `--deploy cloudflare,netlify,github`
54+
- `--out-dir <dir>` (default `api-out`, configurable; **ignored by the Cloudflare adapter template**)
55+
- `--deploy cloudflare,netlify,github`
56+
_(non-Cloudflare templates only; the Cloudflare adapter template always targets Workers)_
4957
- `--help, -h`
5058

5159
**Examples**
@@ -58,9 +66,36 @@ create-statikapi my-api --template dynamic --no-install
5866
create-statikapi my-api --src-dir api --out-dir public/api --deploy cloudflare,github
5967
```
6068

69+
```bash
70+
# Cloudflare Worker adapter (serverless mode)
71+
create-statikapi my-worker --template cloudflare-adapter
72+
```
73+
74+
---
75+
76+
## Cloudflare adapter template (high-level)
77+
78+
When you choose `cloudflare-adapter`, the scaffolder:
79+
80+
- Copies a **Worker + R2 + KV** boilerplate
81+
- Prompts you for:
82+
- **R2 bucket binding name** and **bucket_name**
83+
- **KV namespace binding** and **id**
84+
- **`STATIK_BUILD_TOKEN`** (used to authorize `/build`)
85+
- **`STATIK_SRC`** (defaults to `src-api`)
86+
- **`STATIK_USE_INDEX_JSON`** (whether to favor `/foo/index.json` vs `/foo.json` style)
87+
- Patches `wrangler.toml` with the values you provide
88+
89+
From there you can:
90+
91+
- Run the dev scripts (based on `wrangler dev` + bundling)
92+
- Deploy the Worker to Cloudflare
93+
- Trigger builds via the `/build` webhook documented in
94+
[Serverless Adapters → Cloudflare Worker + R2](../serverless/cloudflare-adapter)
95+
6196
---
6297

6398
## Exit codes
6499

65100
- `0` success
66-
- nonzero indicates an error (parsing, user module errors, etc.)
101+
- non-zero indicates an error (parsing, user module errors, etc.)

docs/getting-started.mdx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
Welcome to **StatikAPI** — generate **static JSON endpoints** from small JS/TS modules.
44

5-
This guide shows two flows:
5+
This guide shows three flows:
66

77
- **From scratch** using `create-statikapi`
88
- **Inside an existing repo** by adding the CLI and a `src-api/` folder _(this directory is configurable via your [configuration](./config))_
9+
- **Serverless mode** using the **Cloudflare Worker adapter** (StatikAPI behind a Worker + R2 + KV, with a build webhook)
910

1011
---
1112

@@ -43,11 +44,41 @@ npm run dev
4344

4445
You will be prompted for:
4546

46-
- **Template**: `basic`, `dynamic`, or `remote-data`
47+
- **Template**: `basic`, `dynamic`, `remote-data`, or
48+
`cloudflare-adapter` (Cloudflare Worker + R2 + KV + build webhook)
4749
- **Package manager** and whether to install now
48-
- Optional ESLint, TS, directories, and deploy presets
50+
- Optional ESLint, TS, directories, and deploy presets
51+
_(ESLint/TS are disabled for the Cloudflare adapter template; it ships ready-to-run JS Worker boilerplate.)_
4952

50-
The dev server watches your **source directory** (default `src-api/`, configurable via [Configuration](./config)) and serves a local **UI** at `/_ui` with a live manifest, JSON previews, and copy-ready code snippets.
53+
The dev server for normal templates watches your **source directory** (default `src-api/`, configurable via [Configuration](./config)) and serves a local **UI** at `/_ui` with a live manifest, JSON previews, and copy-ready code snippets.
54+
55+
---
56+
57+
## 1b) Using the Cloudflare Worker adapter (serverless mode)
58+
59+
If you pick the **`cloudflare-adapter`** template, `create-statikapi` scaffolds:
60+
61+
- A **Cloudflare Worker** wired to:
62+
- **R2** (stores built JSON)
63+
- **KV** (stores the manifest)
64+
- A **build webhook endpoint** on the Worker (`/build`)
65+
- A default **JS-only** boilerplate (no TypeScript / ESLint)
66+
67+
From there you can:
68+
69+
- Run the bundled dev commands to iterate locally
70+
- Deploy the Worker to Cloudflare
71+
- **Trigger rebuilds via HTTP**:
72+
- `POST /build` — rebuild **all routes**
73+
- `POST /build?route=/users/1` — rebuild just that route
74+
75+
Authentication is handled via a **`STATIK_BUILD_TOKEN`** env var on the Worker.
76+
Clients include this token in requests (see [Cloudflare Worker + R2 Adapter](./serverless/cloudflare-adapter) for full details and `curl` examples).
77+
78+
This mode is ideal when:
79+
80+
- You want StatikAPI’s DX, but need a **serverless endpoint** instead of raw static hosting
81+
- Your data changes frequently and you want to **trigger updates via webhooks** from other systems
5182

5283
---
5384

@@ -141,3 +172,4 @@ api-out/ # generated JSON (also configurable via Configuration)
141172
- Read the **CLI Commands** to learn each flag
142173
- Learn the **Routing** model (static, dynamic, catch-all, remote)
143174
- Use **data()** and **paths()** to shape your endpoints
175+
- Explore the **[Cloudflare Worker + R2 adapter](./serverless/cloudflare-adapter)** if you want StatikAPI behind a serverless Worker with a build webhook

0 commit comments

Comments
 (0)