Skip to content

Add bunny.net edge script + deploy workflow (geo-pricing, deployable half) - #13

Closed
taobojlen wants to merge 1 commit into
mainfrom
edge-script-deploy
Closed

Add bunny.net edge script + deploy workflow (geo-pricing, deployable half)#13
taobojlen wants to merge 1 commit into
mainfrom
edge-script-deploy

Conversation

@taobojlen

Copy link
Copy Markdown
Member

Test plan, merge order below. This PR is the deployable half of geo-localized pricing — the edge script + its deploy workflow — split out so it can be merged to main and dispatched for testing before the website changes land.

What

The bunny.net middleware edge script that rewrites the displayed price based on the visitor's country (CDN-RequestCountryCode), plus the manual GitHub workflow to deploy it.

Visitor Price shown
UK (GB, GG, JE, IM) £25/year (static default, untouched)
Everywhere else $35/year (edge script rewrites data-price elements)

Why split from #10

Manual workflows (workflow_dispatch) only run from main. To test the edge script end-to-end (deploy it → attach to staging pull zone → verify the rewrite), the workflow file needs to be on main first. Same pattern that worked for the staging site deploy.

Safe to merge independently

The script only rewrites elements with data-price="" attributes. Those attributes don't exist on the site yet (they arrive in the companion website PR #10). Until then, the script is a no-op on every page — it runs, finds nothing to rewrite, passes the response through. Merging this first carries no risk.

Files

Edge script (edge-script/):

  • src/pricing.ts — middleware: reads cdn-requestcountrycode, rewrites [data-price] for non-UK via HTMLRewriter
  • src/main.ts — entry point
  • src/bunny-globals.d.ts — ambient types for HTMLRewriter (bunny runtime global)
  • build.mjs + deno.json — esbuild bundle to single dist/index.ts
  • README.md — full setup/deploy/verify docs

Deploy:

  • .github/workflows/deploy-edge-script.yml — manual-dispatch: type-check + bundle + upload (secrets: BUNNY_STAGING_SCRIPT_ID, BUNNY_STAGING_DEPLOY_KEY)

Verified

  • deno check src/main.ts
  • deno task build
  • zizmor ✅ (no findings)

Test plan (merge order)

  1. Merge this PRdeploy-edge-script.yml lands on main.
  2. Create the middleware edge script in the bunny dashboard + attach to the staging pull zone (see edge-script/README.md).
  3. Add secrets BUNNY_STAGING_SCRIPT_ID + BUNNY_STAGING_DEPLOY_KEY.
  4. Run "Deploy edge script (staging)" workflow (dispatch against main).
  5. Verify the script is live on staging (bunny dashboard → Script → Logs, or check for the middleware processing requests).
  6. Then merge Add geo-localized pricing via bunny.net edge script #10 (website data-price markers) + re-deploy the staging site → full geo-pricing test.

Adds the bunny.net middleware edge script that rewrites the displayed price
based on the visitor's country (CDN-RequestCountryCode), plus the manual
workflow to deploy it. This is the deployable half of geo-localized pricing;
the website changes (data-price markers) arrive separately.

Edge script (edge-script/):
- Middleware using servePullZone + HTMLRewriter. Non-UK visitors get
  $35/year; UK/unknown visitors see the static default (£25/year) baked into
  the HTML. Safe degradation if the script is disabled or the header is
  missing.
- Bundled to a single file via esbuild + @luca/esbuild-deno-loader (mirrors
  the official BunnyWay template).

Deploy:
- deploy-edge-script.yml: manual-dispatch workflow. Type-checks, bundles, and
  uploads the edge script to a bunny edge script id. Secrets:
  BUNNY_STAGING_SCRIPT_ID / BUNNY_STAGING_DEPLOY_KEY.

The script is generic and safe to merge independently: it only rewrites
elements with data-price="" attributes, which don't exist on the site yet
(those arrive with the website changes). Until then it's a no-op on every
page, so merging this first carries no risk.
@taobojlen taobojlen closed this Jul 24, 2026
@taobojlen
taobojlen deleted the edge-script-deploy branch July 24, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant