WOOSTACK

Deploy a full-stack Cloudflare Worker

Release an Astro public site, React SPA, and Hono API together on two hostnames with one Worker.

Deploy separate Astro and React/Vite apps with a Hono API as one Cloudflare Worker. The public site runs at example.com; the app and its /api endpoints run at app.example.com. Both frontends use / as their public base.

You need:

  • A pnpm workspace with working builds for an Astro static site, a React/Vite SPA using standalone TanStack Router, and a Hono API compatible with Workers.
  • Wrangler installed in the API app, a GitHub repository, and permission to configure Actions.
  • A Cloudflare account with an active zone for your domain and permission to attach both hostnames.
  • Non-production database and auth resources for preview checks, plus the intended production bindings.

The example paths describe your application, not the Woostack documentation site. Replace the hostnames and adapt paths to your repository. This is a deployment guide, not a complete app scaffold: the asset assembly script and hostname dispatcher are project-owned code that must exist before verification.

For the design and its tradeoffs, see Runtime architecture. To deploy this documentation site instead, use the docs app README.

1. Configure the application

Build both frontends into separate asset namespaces

Keep the source apps separate. For the example layout, apps/site builds the public site, apps/app builds the SPA, and apps/api owns the Worker entrypoint and Wrangler configuration.

  1. Build the SPA with Vite's base and TanStack Router's basepath set to /, not /app/.

  2. Set Astro's site to your public origin, such as https://example.com. Use static output, build.format: "directory", and trailingSlash: "always" for the URL mapping below. Static output needs no server adapter.

  3. Have your build script assemble both outputs into one clean generated directory:

    Copy the contents ofIntoPublic host
    apps/site/dist/dist/assets/site/example.com
    apps/app/dist/dist/assets/app/app.example.com

Keep the Worker bundle outside dist/assets/ and ignore generated output in Git. Use the same assembly script locally and in CI. The result should include site/index.html, site/_astro/, app/index.html, and app/assets/ beneath dist/assets/. The site and app prefixes are internal storage namespaces, never public URL prefixes.

If either build emits _headers or _redirects, move the required rules into hostname-aware Worker handling and exclude those metadata files from uploaded assets. Preserve security headers; do not combine both apps' catch-all redirects.

If your public site includes documentation, integrate Fumadocs with Astro there and prerender /docs/ pages. Generate its static search index in the same build, with the client loading a root-host path such as /docs/search-index.json. Do not copy the integration example's /api/search path: this topology reserves /api for the app host. Include article HTML, search data, and client assets in the site output.

Configure one Worker and two Custom Domains

For apps/api/src/index.ts as the Worker entrypoint, adapt this apps/api/wrangler.jsonc. The compatibility date is illustrative; use the date your project has tested.

{
  "name": "fullstack-app",
  "main": "./src/index.ts",
  "compatibility_date": "2026-10-25",
  "workers_dev": false,
  "preview_urls": false,
  "routes": [
    { "pattern": "example.com", "custom_domain": true },
    { "pattern": "app.example.com", "custom_domain": true }
  ],
  "assets": {
    "directory": "../../dist/assets",
    "binding": "ASSETS",
    "html_handling": "none",
    "not_found_handling": "none",
    "run_worker_first": true
  }
}

Both Custom Domains attach to this Worker. They are exact hostnames, not wildcard path routes. Resolve conflicting DNS records before attaching them. This production configuration disables alternate workers.dev and preview URLs. Give each preview its own Worker, hostname pair, dispatch configuration, and data; do not attach production domains to a preview.

Implement hostname dispatch before asset lookup

The Wrangler configuration does not select between apps. The ASSETS binding matches only the pathname, so forwarding / unchanged would give both hosts the same file. Worker-first routing ensures the dispatcher runs even when an asset exists. All asset requests invoke Worker code.

Implement the dispatcher in the entrypoint in this order:

  1. Match new URL(request.url).hostname against your two configured hosts. Reject unknown hosts and direct requests to /site, /app, and their descendants. Keep rewritten paths inside the selected namespace, including after decoding or normalization; clients must not select or escape it.
  2. On the app host, pass /api and /api/* to Hono before looking for assets. Preserve the original URL, method, headers, and body. Unknown API routes return API 404 responses. On the root host, return 404 for those paths.
  3. For other GET and HEAD requests, look up the selected file through env.ASSETS.fetch() with an internally rewritten pathname. Preserve the method and relevant headers; HEAD has no response body. Do not use global fetch() to call your public hosts, which would re-enter the Worker.
  4. On an app-host asset miss only, return /app/index.html for HTML navigation. Exclude API paths, /assets/*, file URLs, robots.txt, and sitemaps even when opened in a browser. Other methods and non-HTML requests never receive the shell. Return 404 for remaining misses. A custom public 404 page must retain status 404.

With automatic HTML handling disabled, use these explicit mappings:

Public requestInternal asset lookup
https://example.com//site/index.html
https://example.com/pricing//site/pricing/index.html
https://example.com/docs/getting-started//site/docs/getting-started/index.html
https://example.com/docs/search-index.json/site/docs/search-index.json
https://example.com/_astro/main.css/site/_astro/main.css
https://app.example.com/assets/main.js/app/assets/main.js
https://app.example.com/settings, HTML navigation with no matching asset/app/index.html

The dispatcher also owns canonical redirects because html_handling: "none" disables automatic ones. For an existing public page, redirect /pricing and /pricing/index.html to /pricing/, preserving the query string. Check existence first. Redirects, canonicals, and generated asset links must never expose internal prefixes. Leave global SPA fallback disabled.

Connect authentication and the database

Keep application-to-API calls same-origin, such as /api/health from app.example.com. The root and app hosts are different origins. Use ordinary links to enter the app; public-site browser calls to its API need an explicit CORS policy.

Configure authentication callbacks and allowed origins for the app hostname. Prefer host-scoped application session cookies. Preserve server-side session verification, authorization, and CSRF controls; sharing one Worker does not replace them.

Keep database credentials and auth secrets in Worker secrets or bindings, never in generated HTML or VITE_* variables. Add Hyperdrive and the compatibility flags required by your chosen driver. For permission checks, billing, and read-after-write flows, use a cache-disabled Hyperdrive configuration. Query caching is enabled by default; disabling it retains connection pooling.

If a public page requires request-time SSR, the static configuration above is insufficient. Use the Astro Cloudflare adapter and its supported custom entrypoint to dispatch Astro on the root host and Hono on the app host. Reconcile the generated Worker configuration and assets with the SPA output before continuing.

2. Verify the built application

Run your repository's frontend builds and asset assembly script first. From the repository root, start the combined Worker:

pnpm --dir apps/api exec wrangler dev

Map two local test hostnames to the Worker address and port Wrangler prints, and configure the dispatcher to accept them only in local development. A localhost request alone cannot verify host selection. Keep app dev servers for UI iteration; use this combined build to check deployment behavior.

Before publishing, run these checks. Routes such as /pricing/ and /settings assume your app implements them; substitute real routes with the same role.

CheckExpected result
Fetch / on both hosts without executing JavaScriptRoot returns public HTML and metadata; app returns its shell, never the public homepage.
Fetch a public article, robots.txt, and sitemapCanonicals and sitemap URLs use the production root origin, without internal prefixes, private app routes, or API URLs. Each host serves its own robots policy.
Open a docs deep link without JavaScript, then enable it and searchInitial HTML contains the article; search loads the static root-host index and returns working links. Skip if the site has no docs.
Open and reload an app deep link such as /settingsApp shell, app-host assets, and TanStack Router load correctly.
Call known and unknown /api/* routes on both hostsApp returns API results or API 404; root never exposes Hono.
Request a missing public page and missing files under /_astro/ and /assets/HTTP 404, including direct browser navigation to the files.
Request internal prefixes or files belonging to the other hostNo cross-host asset exposure or successful shell fallback, including encoded or normalized path variants.
Request an existing public page without its canonical slash or through index.htmlRedirect stays on the public host, preserves the query, and hides internal prefixes.
Send a non-HTML request, a non-navigation method, or an unknown hostNo successful shell fallback; unknown host is rejected.
Inspect public, app, and preview responsesProduction public pages are indexable; app shells and previews have the intended noindex. Private data requires authentication.

Use Playwright for critical journeys, including the public-site-to-app transition. Inspect raw responses rather than only the hydrated DOM. Check metadata against the SEO expectations and validate structured data, if present, with Google's Rich Results Test.

Repeat both-host checks over HTTPS in a trusted preview. Verify managed Neon Auth login, session restoration, authenticated requests, and logout there, including callback URLs and cookie scope. A local Better Auth fixture cannot prove managed-provider integration.

Common failures

SymptomCheck and recoveryConfirmation
Both hosts show the same homepageConfirm Worker-first routing and hostname selection before namespaced ASSETS lookup.Fetching / on each host returns the correct app.
Missing JavaScript receives HTMLExclude file and asset paths from shell fallback; keep global fallback off.Missing assets return 404, not text/html with status 200.
Docs search fails while articles loadCheck the client index URL and that assembly copied the generated index.Search fetches root-host static JSON and opens a result.
Login loops or sessions disappear in previewCheck preview callback URLs, trusted origins, HTTPS, and cookie scope against the managed provider.Login and session restoration succeed on the preview app hostname.
Permission changes appear lateCheck whether the auth module reads through a cached database client.Permission reads use the uncached primary path and reflect committed changes.

3. Configure delivery with GitHub Actions

Use one release pipeline for the Worker and both frontends. Separate app jobs deploying to the same Worker can overwrite each other's assets. Keep untrusted PR verification separate from jobs with production credentials.

  1. Verify pull requests. Install with pnpm install --frozen-lockfile, then run the repository's type, lint, format, and relevant test commands. Build and assemble the complete deployment, then run the Workers checks above. Declare the pnpm version in packageManager and Node for tooling; cache the pnpm store without treating cached dependencies as authoritative.
  2. Deploy trusted previews. Use an isolated preview Worker, hostname pair, non-production bindings, and data. Protect access where needed and apply noindex to reachable preview pages. Run the HTTPS and managed-auth checks before production.
  3. Release production. After required checks pass on main, use a protected GitHub environment and serialize deployments. Release the verified Worker and both asset namespaces together.
  4. Check and record the release. Smoke-check both hostnames, an app deep link, and the API. Record the commit and deployment identity so an operator can identify or roll back the complete release. After release, Search Console and PageSpeed Insights can check indexing and performance.

Cloudflare's GitHub Actions integration supports Wrangler CLI or cloudflare/wrangler-action. Store CLOUDFLARE_API_TOKEN in GitHub environment secrets, limit it to the deployment account and required permissions, and supply CLOUDFLARE_ACCOUNT_ID through the environment. Use read-only repository permissions unless a job needs more, and pin third-party actions to reviewed commit SHAs.

Never pass deployment credentials to forked PRs or run untrusted code with pull_request_target secrets. Disable any second automatic deployment path targeting the same Worker.

Build once for the target environment. If build and deploy are separate jobs, transfer the verified Worker bundle, both asset namespaces, and deployment configuration together. Use Wrangler's --config to select that configuration, ensuring main and assets.directory resolve to the transferred files. For a prebundled Worker, deploy with --no-bundle; framework-generated builds must use their generated deployment config. Do not deploy only one app's output or rebuild unverified artifacts in the release job.

Run production Drizzle Kit migrations through controlled release automation, not inside API requests or from a developer machine. Keep changes compatible with the deployed app and intended rollback. A failed migration stops the dependent release; rolling back a Worker does not restore the schema or data. Record the migration's recovery procedure separately.

Build and deploy on a self-hosted runner

To avoid Cloudflare build minutes and GitHub-hosted runner compute, run the build, checks, and Wrangler deployment on your own machine. GitHub Actions still coordinates the job; Cloudflare receives the built Worker and assets. This is self-hosted execution, not a self-hosted GitHub control plane.

GitHub currently lists self-hosted runner usage as free. You still pay for your machine, storage, networking, and Cloudflare runtime services. GitHub artifact and cache storage have separate billing rules. This example uses neither artifact uploads nor the Actions cache service; all build output stays on the runner until deployment. Standard GitHub-hosted runners are also free for public repositories, so self-hosting is not always a cost saving.

Use this example for a trusted private repository. GitHub recommends against self-hosted runners for public repositories because untrusted workflows can compromise the machine. Do not run PR code on the production runner, even without deployment secrets: a persistent compromise can steal credentials from a later job. Labels select runners; they are not an access-control boundary. Restrict runner access to trusted repositories and workflows, and prefer a clean, single-job ephemeral runner. Use isolated runners without production access for any untrusted verification.

Before enabling the workflow:

  1. Register a self-hosted runner on a dedicated Linux x64 machine with the custom label cloudflare-deploy. Keep its runner software current and compatible with the pinned checkout action. Preinstall Git, the project's Node and pnpm versions, and any browser or system dependencies needed by its checks. Do not use a personal workstation or retain unrelated credentials on the machine.
  2. Protect main and restrict edits to workflows and release scripts. Configure a production GitHub environment restricted to main, with approval where supported by your repository and plan. Put CLOUDFLARE_API_TOKEN in its secrets and CLOUDFLARE_ACCOUNT_ID in its variables. Environment approval is not runner isolation; trusted build scripts run on the same machine as deployment.
  3. Disconnect the Worker's repository integration so Workers Builds does not also run on pushes. Disabling production deployment alone can still leave builds running. Disable any other pipeline targeting this Worker.
  4. Implement and locally verify the release-script contract below in your application. The names and output paths are proposed examples, not commands shipped by Woostack.
Root package scriptRequired behavior
ci:verifyRuns the project's required type, lint, format, and test checks; exits nonzero on failure.
build:releaseBuilds both frontends, assembles dist/assets/site/ and dist/assets/app/, and emits a prebundled Worker plus dist/worker/wrangler.jsonc. The generated config points main at that bundle and assets.directory at ../assets, and includes the production routes and bindings.
test:releaseChecks the assembled output in the Workers runtime against the both-host acceptance checks above, using non-production resources; stops its local servers when done.
smoke:productionChecks both live HTTPS hosts, an app deep link, and the API; fails if the deployed release is unhealthy. It does not automatically roll back or mutate application data.

Place the adapted workflow at .github/workflows/deploy-production.yml in your application repository. Once enabled, a push to main deploys production; a manual run is accepted only from main. There is deliberately no pull_request, pull_request_target, or workflow_run trigger.

name: Deploy production

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: cloudflare-production
  cancel-in-progress: false

jobs:
  deploy:
    if: github.ref == 'refs/heads/main'
    runs-on: [self-hosted, linux, x64, cloudflare-deploy]
    environment: production
    timeout-minutes: 30
    defaults:
      run:
        shell: bash
    steps:
      - name: Check out the release commit
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - name: Install locked dependencies
        run: pnpm install --frozen-lockfile

      - name: Verify source
        run: pnpm run ci:verify

      - name: Build the complete release
        run: pnpm run build:release

      - name: Verify the built deployment
        run: pnpm run test:release

      - name: Deploy the verified release
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
        run: pnpm --dir apps/api exec wrangler deploy --config ../../dist/worker/wrangler.jsonc --no-bundle

      - name: Check production
        run: pnpm run smoke:production

      - name: Record the release commit
        run: |
          printf 'Release commit: %s\n' "$GITHUB_SHA" >> "$GITHUB_STEP_SUMMARY"

The checkout action is pinned to a release commit; review and update that pin through your normal dependency process. The example assumes Wrangler is a locked dependency of apps/api. Adapt the 30-minute timeout to measured build duration. Build and verification scripts must receive any required non-production configuration explicitly; production credentials are supplied only to the deployment step, not to the whole job. On a persistent machine, step-scoped secrets alone cannot protect against code that has already compromised the runner.

Keep the build and deploy in the same job so Wrangler uploads exactly the output that passed verification, without transferring artifacts through GitHub storage. Do not add a wrangler-action step that rebuilds the application. A repository with schema changes also needs its controlled migration and recovery step before the dependent deployment; this example does not implement one.

A successful run shows the job on your labeled runner, successful both-host smoke checks, the commit in the job summary, and Wrangler's deployment identity in the logs. Confirm that no matching Workers Builds run occurred. If deployment succeeds but smoke checks fail, the new release is already live: inspect the recorded deployment identity and use the established recovery procedure.

If the job remains queued, check that the runner is online, has every requested label, and is allowed to run this repository's workflow. If it waits for environment approval, inspect the production environment's rules. Neither symptom requires switching to a GitHub-hosted runner.

On this page