Skip to content

Commit 0dc4dcd

Browse files
committed
Serve the website from Cloudflare Workers static assets
Add an assets-only Worker for the Astro site, with a staging Custom Domain and a production Custom Domain on www.gecode.dev, and a website option in the edge Worker deployment workflow.
1 parent 06c9fa6 commit 0dc4dcd

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎.github/workflows/workers.yml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030
- documentation
3131
- redirects
3232
- email
33+
- website
3334

3435
permissions:
3536
contents: read
@@ -67,6 +68,12 @@ jobs:
6768
echo "canary operations require the documentation worker" >&2
6869
exit 2
6970
71+
- name: Validate website environment
72+
if: inputs.worker == 'website' && inputs.environment == 'canary'
73+
run: |
74+
echo "the website has staging and production environments only" >&2
75+
exit 2
76+
7077
- name: Validate email environment
7178
if: inputs.worker == 'email' && inputs.environment != 'production'
7279
run: |
@@ -97,6 +104,18 @@ jobs:
97104
if: inputs.worker == 'email'
98105
run: npm run test:email-worker && npm run check:email-worker
99106

107+
- name: Build website
108+
if: inputs.worker == 'website'
109+
run: npm run build:pages && npm run check:website-worker
110+
111+
- name: Deploy website to staging
112+
if: inputs.operation == 'deploy' && inputs.environment == 'staging' && inputs.worker == 'website'
113+
run: npx wrangler deploy --env="" --config workers/website/wrangler.jsonc
114+
115+
- name: Deploy website to production
116+
if: inputs.operation == 'deploy' && inputs.environment == 'production' && inputs.worker == 'website'
117+
run: npx wrangler deploy --env production --config workers/website/wrangler.jsonc
118+
100119
- name: Deploy documentation Worker to staging
101120
if: inputs.operation == 'deploy' && inputs.environment == 'staging' && (inputs.worker == 'both' || inputs.worker == 'documentation')
102121
run: npx wrangler deploy --env="" --config workers/docs/wrangler.jsonc

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"check:docs-hosting": "npm run test:docs-tools && npm run test:docs-worker && npm run check:docs-worker",
1717
"check:docs-worker": "wrangler deploy --dry-run --env canary --config workers/docs/wrangler.jsonc --outdir .wrangler/docs-canary-dry-run && wrangler deploy --dry-run --env production --config workers/docs/wrangler.jsonc --outdir .wrangler/docs-dry-run",
1818
"check:email-worker": "wrangler deploy --dry-run --config workers/email/wrangler.jsonc --outdir .wrangler/email-dry-run",
19-
"check:redirect-worker": "wrangler deploy --dry-run --env production --config workers/redirects/wrangler.jsonc --outdir .wrangler/redirects-dry-run",
19+
"check:website-worker": "wrangler deploy --dry-run --env production --config workers/website/wrangler.jsonc --outdir .wrangler/website-dry-run",
20+
"check:redirect-worker": "wrangler deploy --dry-run --env production --config workers/redirects/wrangler.jsonc --outdir .wrangler/redirects-dry-run",
2021
"check:mode": "./scripts/check-executable-bits.sh",
2122
"check:quality": "npm run build && npm run check:mode && npm run check:html && npm run check:canonical-urls && npm run check:site-semantics && npm run test:content && npm run check:docs-hosting && npm run test:redirect-worker && npm run check:redirect-worker && npm run test:email-worker && npm run check:email-worker",
2223
"dev": "node ./scripts/dev.mjs",

‎workers/website/wrangler.jsonc‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "../../node_modules/wrangler/config-schema.json",
3+
// Static Astro website. Assets only: no Worker script, so requests are
4+
// served from Workers Static Assets without counting as Worker invocations.
5+
// More specific Worker routes on www.gecode.dev (/doc*, /robots.txt*, /e/*
6+
// and classic .html pages) take precedence over this Custom Domain, and
7+
// their fetch() pass-through reaches this Worker as the origin.
8+
"name": "gecode-website-staging",
9+
"compatibility_date": "2026-11-01",
10+
"workers_dev": false,
11+
"assets": {
12+
"directory": "../../_site",
13+
"html_handling": "auto-trailing-slash",
14+
"not_found_handling": "404-page"
15+
},
16+
"routes": [
17+
{ "pattern": "www-staging.gecode.dev", "custom_domain": true }
18+
],
19+
"env": {
20+
"production": {
21+
"name": "gecode-website",
22+
"workers_dev": false,
23+
"assets": {
24+
"directory": "../../_site",
25+
"html_handling": "auto-trailing-slash",
26+
"not_found_handling": "404-page"
27+
},
28+
"routes": [
29+
{ "pattern": "www.gecode.dev", "custom_domain": true }
30+
]
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)