Skip to content

Commit 1f52445

Browse files
committed
docs: expand Deployments with StatikAPI Cloud info and provider guides
1 parent 773c3ce commit 1f52445

7 files changed

Lines changed: 356 additions & 78 deletions

File tree

docs/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "StatikAPI",
33
"description": "Build static JSON endpoints from filesystem modules — like Next.js static export, but for APIs.",
44
"version": "0.4.0",
5-
"lastUpdated": "2025-11-08T00:40:00.000Z",
5+
"lastUpdated": "2025-11-08T01:00:00.000Z",
66
"repo": "https://github.com/zonayedpca/statikapi"
77
}

docs/config.mdx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,3 @@ You can freely use **.ts / .tsx** route files. The CLI transpiles on the fly and
141141
- **`srcDir` and `outDir` must differ** — point them at different folders.
142142
- **Dynamic routes not emitting** — ensure the module exports `paths()` that returns **strings** (or arrays of strings for catch‑all). See **Routes** docs.
143143
- **Non‑serializable value** — only plain objects/arrays, finite numbers, strings, booleans, or `null`. No functions, symbols, BigInt, Dates, classes, or cycles.
144-
145-
---
146-
147-
## See also
148-
149-
- **[CLI → StatikAPI (Core)](./cli/statikapi)** for flags and dev/build usage
150-
- **[Routes](./routes/index)** for file → URL mapping rules
151-
- **[Deployments](./deployments/index)** for hosting static JSON

docs/deployments/amazon-s3.mdx

Lines changed: 124 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,134 @@
11
# Amazon S3
22

3-
Amazon S3 is ideal for large or enterprise-grade static JSON APIs.
3+
Amazon S3 is a solid option for large or enterprisegrade static JSON APIs, especially when paired with **CloudFront** for global CDN delivery.
44

5-
**Steps:**
5+
---
66

7-
1. Build:
8-
```bash
9-
statikapi build
10-
```
7+
## Using the AWS CLI
118

12-
2. Sync to S3:
13-
```bash
14-
aws s3 sync api-out s3://my-bucket-name/ --content-type "application/json"
15-
```
9+
### 1) Build locally
1610

17-
3. Enable static website hosting or serve via CloudFront for CDN distribution.
11+
```bash
12+
npx statikapi build
13+
```
14+
15+
### 2) Sync the output to S3
16+
17+
Use `sync` to mirror your local `api-out/` to a bucket. The AWS CLI will generally infer `Content-Type: application/json` for `.json` files. You can also set headers explicitly if needed.
18+
19+
**Basic (let CLI infer content type):**
20+
21+
```bash
22+
aws s3 sync api-out s3://my-bucket-name/ --delete
23+
```
24+
25+
**Force JSON content type for everything (only if all files are JSON):**
26+
27+
```bash
28+
aws s3 sync api-out s3://my-bucket-name/ --delete --content-type "application/json"
29+
```
30+
31+
**Optional caching headers (tune to your needs):**
32+
33+
```bash
34+
# Example: short cache to allow quick updates
35+
aws s3 sync api-out s3://my-bucket-name/ --delete --cache-control "public,max-age=60"
36+
```
37+
38+
> If you also upload non‑JSON assets (rare for a pure API), prefer the basic command so the CLI infers the correct `Content-Type` per file.
39+
40+
### 3) Make objects publicly readable
41+
42+
If you need public access, configure a **Bucket Policy** that allows `s3:GetObject` on the objects. Avoid ACLs if Object Ownership is set to “Bucket owner enforced”.
43+
44+
Minimal example policy (adjust `Resource` ARN to your bucket name/region):
45+
46+
```json
47+
{
48+
"Version": "2012-10-17",
49+
"Statement": [
50+
{
51+
"Sid": "PublicReadGetObject",
52+
"Effect": "Allow",
53+
"Principal": "*",
54+
"Action": "s3:GetObject",
55+
"Resource": "arn:aws:s3:::my-bucket-name/*"
56+
}
57+
]
58+
}
59+
```
60+
61+
---
62+
63+
## Serving options
64+
65+
### Option A — S3 Static Website Hosting
66+
67+
- Enable **Static website hosting** on the bucket.
68+
- Access via the website endpoint (varies by region), for example:
69+
70+
```
71+
http://my-bucket-name.s3-website-us-east-1.amazonaws.com/users/1/index.json
72+
```
73+
74+
### Option B — CloudFront over S3 (recommended for production)
75+
76+
- Create a **CloudFront distribution** with the S3 bucket as the origin.
77+
- Set appropriate caching behavior and headers.
78+
- Access via your CloudFront domain or a custom domain:
79+
80+
```
81+
https://api.example.com/users/1/index.json
82+
```
83+
84+
**Direct S3 object URL (when public):**
1885

19-
**Example URL**
2086
```
2187
https://my-bucket-name.s3.amazonaws.com/users/1/index.json
2288
```
89+
90+
---
91+
92+
## Automation (CI/CD)
93+
94+
Typical GitHub Actions flow using OIDC and the AWS CLI:
95+
96+
```yaml
97+
name: Deploy StatikAPI to S3
98+
on:
99+
push:
100+
branches: [main]
101+
jobs:
102+
deploy:
103+
runs-on: ubuntu-latest
104+
permissions:
105+
id-token: write
106+
contents: read
107+
steps:
108+
- uses: actions/checkout@v4
109+
110+
- name: Configure AWS credentials
111+
uses: aws-actions/configure-aws-credentials@v4
112+
with:
113+
role-to-assume: arn:aws:iam::123456789012:role/gha-oidc-deploy
114+
aws-region: us-east-1
115+
116+
- name: Install deps
117+
run: npm ci
118+
119+
- name: Build API
120+
run: npx statikapi build
121+
122+
- name: Sync to S3
123+
run: aws s3 sync api-out s3://my-bucket-name/ --delete
124+
```
125+
126+
---
127+
128+
## Considerations
129+
130+
- S3 can scale to very large datasets; pair with **CloudFront** for low‑latency global access and fine‑grained caching.
131+
- Prefer **short cache** for frequently updated JSON; increase `max-age` for versioned paths.
132+
- Keep object keys stable if you intend to leverage CDN caching effectively.
133+
- You can also host your APIs directly with **StatikAPI Cloud** _(coming soon)_ — a managed platform for static JSON hosting with automatic builds and versioned deployments.
134+
[Join the waitlist](#subscription) for early access.

docs/deployments/cloudflare.mdx

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,94 @@
11
# Cloudflare Pages & R2
22

3-
Cloudflare is an excellent choice for hosting small or medium static JSON APIs —
4-
especially if you’re already hosting your frontend or documentation there.
3+
Cloudflare is an excellent choice for hosting small or medium static JSON APIs —
4+
especially if you are already hosting your frontend or documentation there.
55

66
---
77

8-
## Using Cloudflare Pages
8+
## Using Cloudflare Pages
99

1010
You can deploy your `api-out/` folder directly to **Cloudflare Pages**:
1111

1212
```bash
1313
npx wrangler pages publish api-out --project-name my-statikapi
1414
```
1515

16-
This works great for:
16+
Cloudflare Pages supports two deployment approaches:
17+
18+
1. **Git Integration** — connect your repository (GitHub, GitLab, or Bitbucket) directly to Cloudflare Pages.
19+
Every time you push changes to your configured branch, Cloudflare will automatically trigger a new build and redeploy your project.
20+
21+
2. **Manual Deployment** — use the `wrangler pages publish` command to upload a local build (as shown above).
22+
This is ideal for projects built by CI/CD pipelines or for static API exports like StatikAPI.
23+
24+
Cloudflare also supports **build hooks and webhooks**, which can trigger rebuilds automatically when your external systems (for example, StatikAPI SaaS or your backend) finish a build.
25+
26+
> Example: You can configure a webhook in Cloudflare Pages and have your StatikAPI build process call it whenever `api-out/` is regenerated.
27+
28+
This approach works great for:
1729
- Small APIs
1830
- Public demo endpoints
19-
- Combined projects (e.g., your docs + JSON API in one Pages site)
31+
- Combined projects (for example, your documentation and JSON API in one Pages site)
2032

21-
Your JSON files will be served from the same CDN edge network that powers Pages.
33+
Your JSON files will be served from the same global CDN edge network that powers Cloudflare Pages.
2234

23-
> **Example URL**
24-
> ```
25-
> https://my-statikapi.pages.dev/api/users/1/index.json
26-
> ```
35+
**Example URL**
36+
```
37+
https://my-statikapi.pages.dev/api/users/1/index.json
38+
```
2739

2840
---
2941

30-
## ⚠️ Fair Usage Policy
42+
## Fair Usage Policy
3143

3244
Cloudflare Pages is primarily designed for **websites**, not large API systems.
3345
If you plan to serve thousands of JSON files or expect high traffic, review their **fair use policy** and bandwidth limits.
3446

35-
**In short:**
36-
- Occasional JSON requests are fine
37-
- API-like workloads with heavy access may be rate-limited or blocked
38-
- Pages cache and limits vary per plan — always check the [Cloudflare Pages Terms of Service](https://developers.cloudflare.com/pages/platform/limits/) and related usage rules.
47+
**Summary:**
48+
- Occasional JSON requests are fine.
49+
- Heavy API-like workloads may be rate-limited or blocked.
50+
- Limits and caching behavior vary per plan — always review the [Cloudflare Pages Limits](https://developers.cloudflare.com/pages/platform/limits/) and Terms of Service.
3951

4052
---
4153

42-
## 💡 For Larger Projects — Use R2
54+
## For Larger Projects — Use R2
55+
56+
If your StatikAPI project produces many JSON files or large objects, consider hosting them in **Cloudflare R2**.
4357

44-
If your StatikAPI project produces **many JSON files** or large objects, host them in **Cloudflare R2**:
58+
R2 is Cloudflare’s object storage service, similar to AWS S3, designed for large data sets and high availability.
4559

46-
1. Upload the entire `api-out/` folder to R2:
47-
```bash
48-
npx wrangler r2 object put my-bucket --file api-out
49-
```
60+
### Upload to R2
5061

51-
2. Configure public access or route it via a Worker:
52-
```js
53-
export default {
54-
async fetch(request) {
55-
// Proxy JSON files from R2
56-
}
57-
};
58-
```
62+
You can upload your entire `api-out/` directory:
5963

60-
R2 gives you:
61-
- Better scalability and cost control
62-
- API-friendly object storage
63-
- Freedom from Pages file limits
64+
```bash
65+
npx wrangler r2 object put my-bucket --file api-out
66+
```
67+
68+
### Serve from R2 or via Workers
69+
70+
You can make your R2 bucket public or serve it behind a Worker:
71+
72+
```js
73+
export default {
74+
async fetch(request) {
75+
// Example: Proxy JSON files from R2
76+
}
77+
};
78+
```
79+
80+
**Advantages of R2**
81+
- Handles large-scale APIs efficiently
82+
- No egress bandwidth fees within Cloudflare
83+
- Can integrate seamlessly with Workers and KV
84+
- Supports advanced routing and caching
6485

6586
---
6687

67-
> **Best practice:**
68-
> - For small JSON sets or static sites → Pages ✅
69-
> - For large datasets or API-style serving → R2 💪
70-
> - Always follow Cloudflare’s latest policies and ToS.
88+
## Considerations
89+
90+
- For **small projects** or when combining with an existing site → use **Cloudflare Pages**
91+
- For **large datasets** or when serving JSON like an API → use **Cloudflare R2**
92+
- Always follow Cloudflare’s current **usage policies and terms** to stay within fair-use limits
93+
- You can also host your APIs directly with **StatikAPI Cloud** *(coming soon)* — a managed hosting solution built for static JSON APIs, automatic builds, and versioned deployments.
94+
[Join the waitlist](#subscription) to get early access.

docs/deployments/github-pages.mdx

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,69 @@
11
# GitHub Pages
22

3-
GitHub Pages can serve JSON just like HTML.
3+
GitHub Pages can serve JSON files just like regular static assets.
44

5-
1. Commit your `api-out/` directory.
6-
2. Push it to a `gh-pages` branch (or `/docs` folder).
7-
3. Enable Pages in repo settings.
5+
---
6+
7+
## Manual Deployment
8+
9+
You can manually commit and push your `api-out/` directory to a branch or folder used by GitHub Pages.
810

911
```bash
1012
git add api-out
1113
git commit -m "Add API output"
1214
git subtree push --prefix api-out origin gh-pages
1315
```
1416

15-
Your endpoints will be accessible at:
17+
Your endpoints will be publicly accessible at:
18+
1619
```
1720
https://username.github.io/repo-name/users/1/index.json
1821
```
1922

20-
> For automation, use GitHub Actions to build and push after every commit.
23+
---
24+
25+
## Git Integration
26+
27+
GitHub Pages automatically builds and serves content from specific branches (`gh-pages`, `main`, or `docs/` folders depending on settings).
28+
Once your repository is configured for Pages, any push to the target branch will trigger an automatic redeploy of your static JSON API.
29+
30+
---
31+
32+
## Automation with GitHub Actions
33+
34+
You can automate your StatikAPI build and deployment using **GitHub Actions**.
35+
36+
Example workflow snippet:
37+
38+
```yaml
39+
name: Deploy StatikAPI
40+
on:
41+
push:
42+
branches: [main]
43+
jobs:
44+
build:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Install dependencies
49+
run: npm ci
50+
- name: Build API
51+
run: npx statikapi build
52+
- name: Deploy to GitHub Pages
53+
uses: peaceiris/actions-gh-pages@v3
54+
with:
55+
github_token: ${{ secrets.GITHUB_TOKEN }}
56+
publish_dir: ./api-out
57+
```
58+
59+
This workflow ensures that every commit to `main` automatically rebuilds and deploys your JSON endpoints to GitHub Pages.
60+
61+
---
62+
63+
## Considerations
64+
65+
- Best for **small APIs**, demos, and documentation datasets.
66+
- GitHub Pages has limited bandwidth and file size per repository.
67+
- For **larger or dynamic datasets**, consider using **Cloudflare R2**, **Amazon S3**, or another CDN-backed object storage.
68+
- You can also host your APIs directly with **StatikAPI Cloud** _(coming soon)_ — a managed hosting platform with automatic builds, caching, and versioned JSON hosting.
69+
[Join the waitlist](#subscription) for early access.

0 commit comments

Comments
 (0)