Skip to content

Commit 4231a3d

Browse files
committed
implement global CDN cache priming layer
create API that invalidates ISR builds, clears global CDN caches, and warms pages API has zod schema, openAPI contract and documentation refactor botconfig to depend on API by default to manage ISR refactor sitemap to be SSR and record a build time file to track time updates over time with ISR setup zod runtime validation configs refactor Cloudflare worker to be primary ISR manager via cronjob API calls Cloudflare worker no longer manually handle warming behaviors, instead relying on new priming API call to handle them update and add testing for all the above via vitest and playwright fixtures update GitHub Actions e2e workflow to run API test update GitHub Actions deployment workflow to manage initial deployment CDN priming via API call
1 parent 4e3eac6 commit 4231a3d

55 files changed

Lines changed: 5083 additions & 1009 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# API Config
2+
API_DRY_RUN=false
3+
4+
# Sitemap configurations
5+
## Manages how often the sitemap says its updated from after most recent deployment
6+
SITEMAP_REVALIDATE_SECONDS=518400
7+
18
# Performance Redirect Hook for test environments with low-end specs (enabled by default as intended, set "false" to turn it off)
29
NEXT_PUBLIC_DISABLE_PERF_REDIRECT=false
310

@@ -21,6 +28,7 @@ ENABLE_CHROME_MOBILE=true
2128
ENABLE_FIREFOX_DESKTOP=true
2229
ENABLE_FIREFOX_MOBILE=true
2330

24-
# Testing Cloudflare via Playwright Fixture
31+
# Cloudflare Worker & Revalidation API (shared secret)
32+
# Used by both the Cloudflare warm worker and /api/revalidate endpoint
2533
PRIMER_WORKER_URL=
2634
PRIMER_AUTH_SECRET=

.github/workflows/deploy-vercel.yml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ jobs:
2323
- name: Setup pnpm
2424
uses: pnpm/action-setup@v4
2525

26+
- name: Generate build timestamp
27+
run: |
28+
mkdir -p lib/generated
29+
echo "// Auto-generated at build time - do not edit" > lib/generated/buildTime.ts
30+
echo "export const BUILD_TIME = '$(date -u +'%Y-%m-%dT%H:%M:%SZ')';" >> lib/generated/buildTime.ts
31+
cat lib/generated/buildTime.ts
32+
2633
- name: Deploy to Vercel (prod, cold build) via CLI
2734
id: vercel
2835
env:
@@ -69,32 +76,52 @@ jobs:
6976
# Back-compat output
7077
echo "preview-name=$DEPLOY_URL" >> "$GITHUB_OUTPUT"
7178
72-
- name: Warm Next.js pages (Cloudflare Worker)
79+
- name: Revalidate + prime all Next.js pages (on-demand ISR + CDN priming)
80+
if: ${{ success() }}
81+
env:
82+
REVALIDATE_URL: https://carolinevreeland.com/api/revalidate
83+
REVALIDATE_SECRET: ${{ secrets.PRIMER_AUTH_SECRET }}
84+
run: |
85+
set -euo pipefail
86+
if [ -z "${REVALIDATE_SECRET:-}" ]; then
87+
echo "Revalidate + prime step skipped: PRIMER_AUTH_SECRET not set."
88+
exit 0
89+
fi
90+
91+
status="$(curl -s -o /dev/null -w "%{http_code}" -X POST "${REVALIDATE_URL}?target=all&warm=true" \
92+
-H "X-Auth: ${REVALIDATE_SECRET}" || true)"
93+
94+
case "$status" in
95+
2*) echo "Revalidate + prime OK ($status)";;
96+
*) echo "Revalidate + prime returned HTTP $status. Continuing.";;
97+
esac
98+
99+
- name: Prime Next.js pages (Cloudflare Worker)
73100
if: ${{ success() }}
74101
env:
75-
WARM_URL: ${{ secrets.WARM_WEBHOOK_URL }}
76-
WARM_AUTH: ${{ secrets.WARM_AUTH_SECRET }}
102+
PRIMER_URL: ${{ secrets.PRIMER_WORKER_URL }}
103+
PRIMER_AUTH: ${{ secrets.PRIMER_AUTH_SECRET }}
77104
run: |
78105
set -euo pipefail
79-
# Make the warm webhook non-blocking: log result and continue even on failure/404/missing secrets
80-
if [ -z "${WARM_URL:-}" ] || [ -z "${WARM_AUTH:-}" ]; then
81-
echo "Warm step skipped: WARM_URL and/or WARM_AUTH not set."
106+
# Make the prime webhook non-blocking: log result and continue even on failure/404/missing secrets
107+
if [ -z "${PRIMER_URL:-}" ] || [ -z "${PRIMER_AUTH:-}" ]; then
108+
echo "Prime step skipped: PRIMER_URL and/or PRIMER_AUTH not set."
82109
exit 0
83110
fi
84111
85112
TS="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
86113
RUN_ID="${{ github.run_id }}"
87114
BODY="{\"event\":\"deploy_ready\",\"env\":\"production\",\"timestamp\":\"$TS\",\"run_id\":\"$RUN_ID\"}"
88-
BASE="${WARM_URL%/}" # strip trailing slash if present
115+
BASE="${PRIMER_URL%/}" # strip trailing slash if present
89116
90-
status="$(curl -s -o /dev/null -w "%{http_code}" -X POST "${BASE}/warm" \
117+
status="$(curl -s -o /dev/null -w "%{http_code}" -X POST "${BASE}/prime" \
91118
-H "Content-Type: application/json" \
92-
-H "X-Auth: ${WARM_AUTH}" \
119+
-H "X-Auth: ${PRIMER_AUTH}" \
93120
--data "${BODY}" || true)"
94121
95122
case "$status" in
96-
2*|3*) echo "Warm OK ($status)";;
97-
404) echo "Warm endpoint returned 404 (missing route). Continuing.";;
98-
0) echo "Warm call did not complete (network error). Continuing.";;
99-
*) echo "Warm webhook returned HTTP $status. Continuing.";;
123+
2*|3*) echo "Prime OK ($status)";;
124+
404) echo "Prime endpoint returned 404 (missing route). Continuing.";;
125+
0) echo "Prime call did not complete (network error). Continuing.";;
126+
*) echo "Prime webhook returned HTTP $status. Continuing.";;
100127
esac

.github/workflows/e2e-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
run: pnpm exec playwright install --with-deps
3535

3636
- name: Run E2E tests
37+
env:
38+
RUN_REVALIDATE: '1'
39+
PRIMER_AUTH_SECRET: 'test-secret'
3740
run: pnpm e2e:stable
3841

3942
- name: Upload test results

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ yarn-error.log*
4343
*.tsbuildinfo
4444
next-env.d.ts
4545

46+
# Generated files
47+
lib/generated/
4648

4749
# Cloudflare
4850
Cloudflare/node_modules

Cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dev": "wrangler dev --local --persist",
88
"deploy": "wrangler deploy",
99
"tail": "wrangler tail",
10-
"secret:auth": "wrangler secret put AUTH_SECRET",
10+
"secret:auth": "wrangler secret put PRIMER_AUTH_SECRET",
1111
"secret:check": "pnpm exec wrangler secret list",
1212
"kv:ids": "wrangler kv namespace list",
1313
"test": "vitest --run",

0 commit comments

Comments
 (0)