Documentation Frameworks and migration

Move a static site from Cloudflare Workers to Gregale

Deploy the same static build to an isolated Gregale URL and verify HTML, assets and routes before changing DNS.

~4 min read
On this page

If your Worker only publishes a build directory, you can deploy the same static output to a separate Gregale app. Check the HTML, assets and routes on the Gregale URL before deciding whether to move the domain. The current Worker, API and database can stay where they are.

If the only problem is wrangler login opening a browser, you may not need to move at all. Run Wrangler with a scoped API token and an explicit account ID. You can do this in a local agent shell without setting up CI. Get the token from the account that owns the Worker and inject it as a secret. Do not add it to the source tree.

Decide what can move first

In the Workers projectOn the Gregale preview
assets.directory serves a static build such as dist/Build the same directory and serve it from an HTTP container. You do not need Wrangler to deploy it.
A main script handles SSR, forms, auth or API routesKeep this logic on Workers until you port it to your runtime. Serving the build directory does not replace the script.
ASSETS, KV, D1, R2, Durable Objects or service bindingsInspect where the Worker uses each binding. Gregale does not import the Wrangler configuration or recreate those bindings.
Redirects, custom headers, HTML handling or SPA fallbackReproduce and test each rule you depend on. A missing file must not return the homepage unless you intentionally configured that fallback.
API hosted elsewhereLeave it there. If the preview needs it, check allowed origins, cookies and callback URLs first. Use test accounts or test endpoints for write paths.

Read the Workers Static Assets configuration alongside your wrangler.jsonc or wrangler.toml. An assets.directory entry alone does not prove every request bypasses Worker code: check main and run_worker_first too.

Deploy the same build to a second URL

Download the Harbor Notes starter. It includes a Wrangler config for the source layout and a Dockerfile for the Gregale target. Both use the same static build script. The demo has two HTML routes and a fingerprinted stylesheet. It makes no API calls.

Use Node.js, jq, curl and the Gregale CLI. Check the signed-in account with gregale whoami before continuing. If Claude Code runs this from a fresh shell, issue it a scoped Gregale key and inject it through GREGALE_TOKEN. Keep CLI permissions and any applicable approval gates on. Do not put the key in a prompt, the source tree or the Docker image.

From the unpacked sample, run the following blocks in the same shell. The first block picks a fresh slug and stops unless the remote plan names that exact slug as a new app. A local --preview is not sufficient for this check.

sh
set -eu
APP="harbor-preview-$(node -p "require('node:crypto').randomBytes(12).toString('hex')")"
REV=v1
printf '%s\n' "$REV" > revision.txt
node build.mjs "$REV"

PLAN=$(gregale --non-interactive --json deploy --name "$APP" --dry-run)
printf '%s\n' "$PLAN" | jq -e --arg app "$APP" '
  .slug == $app and .preview.app == $app
  and .preview.target == "new app" and .blocking == false
' >/dev/null || { echo "Stopped: plan must target a new, unblocked app." >&2; exit 1; }

RELEASE=$(gregale --non-interactive --json deploy --name "$APP" --no-require-authn --rollout immediate --yes --wait)
APP_ID=$(printf '%s\n' "$RELEASE" | jq -er '.app_id | strings | select(length > 0)')
BASE=$(printf '%s\n' "$RELEASE" | jq -er '
  select(.status == "live" and .traffic_percent == 100) | .app_url | strings
')

Use immediate rollout and public access only for this disposable sample. For unreleased content, keep request authentication on and authenticate your verification requests; an unshared URL and noindex do not restrict access.

Verify what the URL serves

A healthy listener or HTTP 200 alone does not prove the intended build is serving. Check both pages, the stylesheet they actually reference and the response for a missing asset:

sh
verify_preview() (
  set -eu
  origin=$1
  revision=$2
  tmp=$(mktemp -d)
  trap 'rm -rf "$tmp"' EXIT
  asset=$(grep -oE '/assets/site\.[0-9a-f]{12}\.css' dist/index.html)
  curl -fsS --max-time 30 "$origin/" -o "$tmp/home"
  curl -fsS --max-time 30 "$origin/about/" -o "$tmp/about"
  for page in "$tmp/home" "$tmp/about"; do
    grep -Fq "data-revision=\"$revision\"" "$page"
    grep -Fq "href=\"$asset\"" "$page"
  done
  curl -fsS --max-time 30 "$origin$asset" -o "$tmp/site.css"
  cmp "dist$asset" "$tmp/site.css"
  status=$(curl -sS --max-time 30 -o "$tmp/missing" -w '%{http_code}' \
    "$origin/assets/does-not-exist.css")
  test "$status" = 404
  grep -Fq 'Harbor Notes: not found' "$tmp/missing"
)
verify_preview "$BASE" "$REV"

For the second release, check the app ID before writing again. A successful second run proves that the updated content and stylesheet are served on the same URL.

sh
CURRENT=$(gregale --non-interactive --json app get "$APP" | jq -er '.id')
test "$CURRENT" = "$APP_ID"
REV=v2
printf '%s\n' "$REV" > revision.txt
node build.mjs "$REV"
RELEASE=$(gregale --non-interactive --json deploy --name "$APP" --rollout immediate --yes --wait)
printf '%s\n' "$RELEASE" | jq -e --arg id "$APP_ID" --arg url "$BASE" '
  .app_id == $id and .app_url == $url and .status == "live" and .traffic_percent == 100
' >/dev/null
verify_preview "$BASE" "$REV"

If you serve cached assets on your own site, also test whether an old browser tab can still load the filenames it references. When finished, delete only the disposable app after checking its ID again: gregale app get "$APP" --json then gregale app delete "$APP".

Leave the production domain on Cloudflare during this test. If you later choose to switch it, first check canonical URLs, redirects, cache headers, indexing settings and any browser calls into your backend. Attach and verify the domain using the custom domains guide rather than copying the sample's preview settings into production.

Cloudflare Workers free tier limits lists the daily request and CPU limits and what happens past them. Proxy one Cloudflare Worker route to FastAPI keeps the Worker and its URL and sends one path to a FastAPI backend.

Spotted a problem on this page? Tell us