Skip to content

Commit d4ea772

Browse files
committed
Convert from Netlify to Cloudflare Workers with static assets
- wrangler.toml: Workers project config serving Hugo output from public/ - src/worker.ts: Minimal worker entry point with ASSETS binding and stub for future API routes (KV, D1, redirects) - package.json: Build/dev/preview/deploy scripts with wrangler v4 - tsconfig.json: TypeScript config for worker source - .github/workflows/deploy.yml: CI/CD pipeline — builds Hugo and deploys via wrangler on push to master - .gitignore: Add .wrangler/ directory - docs/ARCHITECTURE.md: Update hosting/deployment docs Manual steps required: - Add CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID as GitHub secrets - Add custom domain tshark.dev to the Workers project - Disable Netlify deployment
1 parent 6d05e81 commit d4ea772

7 files changed

Lines changed: 111 additions & 10 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Deploy to Cloudflare Workers
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0 # Needed for enableGitInfo
14+
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 22
18+
cache: npm
19+
20+
- name: Install Hugo
21+
uses: peaceiris/actions-hugo@v3
22+
with:
23+
hugo-version: latest
24+
extended: true
25+
26+
- run: npm ci
27+
- run: npm run build
28+
29+
- name: Deploy to Cloudflare Workers
30+
uses: cloudflare/wrangler-action@v3
31+
with:
32+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
33+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
node_modules/
1010
package-lock.json
1111

12+
# Cloudflare Workers
13+
.wrangler/
14+
1215
# generated
1316
__pycache__/
1417
_gen/

docs/ARCHITECTURE.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- **Live site:** https://tshark.dev
88
- **Source:** https://github.com/pocc/tshark.dev
9-
- **Hosting:** Netlify (auto-deploys from GitHub)
9+
- **Hosting:** Cloudflare Workers (auto-deploys via GitHub Actions)
1010
- **Generator:** [Hugo](https://gohugo.io/) (static site generator, Go-based)
1111
- **Theme:** [Hugo Learn Theme](https://learn.netlify.com/en/) (customized)
1212
- **Language:** English only (i18n files exist for 10 languages but only English is active)
@@ -28,10 +28,9 @@
2828
| Content format | Markdown with YAML front matter |
2929
| Syntax highlighting | Hugo Pygments (Chroma) with CSS classes |
3030
| Search | Lunr.js (client-side full-text search) |
31-
| Analytics | Google Analytics (UA-143435644-1) |
32-
| Code highlighting | highlight.js (Atom One Dark Reasonable) |
31+
| Code highlighting | Hugo Chroma (build-time, github/github-dark) |
3332
| Icons | Font Awesome 5 (minified custom subset) |
34-
| Fonts | Open Sans, Roboto, Source Code Pro (self-hosted woff2) |
33+
| Fonts | Inter, JetBrains Mono (Google Fonts) + legacy woff2 |
3534
| Comments | Disabled (Disqus template exists but commented out) |
3635
| Charts | Google Charts (pie chart on Format Usage page) |
3736
| Data tables | jQuery DataTables (pcap search table) |
@@ -116,19 +115,36 @@ The site overrides several Learn Theme partials:
116115
## Build & Development
117116

118117
```bash
119-
# Serve locally (requires Hugo installed)
120-
hugo server
118+
# Install dependencies (wrangler)
119+
npm install
120+
121+
# Serve locally via Hugo dev server
122+
npm run dev
121123
# Default: http://localhost:1313
122124

123125
# Build static site
124-
hugo
125-
```
126+
npm run build
126127

127-
No npm, no build pipeline. Hugo is the only build dependency.
128+
# Preview via Cloudflare Workers local runtime
129+
npm run preview
130+
# Default: http://localhost:8787
131+
132+
# Deploy to Cloudflare Workers
133+
npm run deploy
134+
```
128135

129136
## Deployment
130137

131-
Deployed via Netlify. Push to GitHub triggers an automatic build and deploy. The Netlify badge in README confirms this: `pedantic-lumiere-bf6286`.
138+
Deployed via **Cloudflare Workers** with static assets. Two deployment paths:
139+
140+
1. **GitHub Actions** (automatic): Push to `master` triggers `.github/workflows/deploy.yml` which builds Hugo and runs `wrangler deploy`. Requires `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` repo secrets.
141+
2. **Local** (manual): Run `npm run deploy` to build and deploy from your machine.
142+
143+
### Worker Architecture
144+
145+
- **`wrangler.toml`** — Workers project config, static assets from `public/`
146+
- **`src/worker.ts`** — Worker entry point, serves static assets with stub for future API routes
147+
- **`package.json`** — Build/deploy scripts, wrangler as devDependency
132148

133149
## Key Features
134150

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"build": "hugo --gc --minify",
5+
"dev": "hugo server",
6+
"preview": "npm run build && wrangler dev",
7+
"deploy": "npm run build && wrangler deploy"
8+
},
9+
"devDependencies": {
10+
"wrangler": "^4"
11+
}
12+
}

src/worker.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface Env {
2+
ASSETS: Fetcher;
3+
}
4+
5+
export default {
6+
async fetch(request: Request, env: Env): Promise<Response> {
7+
const url = new URL(request.url);
8+
9+
// Future API routes go here:
10+
// if (url.pathname.startsWith("/api/")) {
11+
// return handleApi(request, env);
12+
// }
13+
14+
// Serve static assets from Hugo's public/ directory
15+
return env.ASSETS.fetch(request);
16+
},
17+
} satisfies ExportedHandler<Env>;

tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"moduleResolution": "bundler",
6+
"lib": ["ESNext"],
7+
"types": ["@cloudflare/workers-types"],
8+
"strict": true,
9+
"noEmit": true,
10+
"skipLibCheck": true
11+
},
12+
"include": ["src"]
13+
}

wrangler.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = "tshark-dev"
2+
main = "src/worker.ts"
3+
compatibility_date = "2025-12-01"
4+
compatibility_flags = ["nodejs_compat"]
5+
6+
[assets]
7+
directory = "public"

0 commit comments

Comments
 (0)