Skip to content

vite dev drops zone before Miniflare, causing CF-Worker to fall back to <worker>.example.com #13791

Description

@mihaip

What versions & operating system are you using?

System:
  OS: macOS 15.7.3
  CPU: (12) arm64 Apple M2 Max
  Memory: 1.06 GB / 64.00 GB
  Shell: 3.2.57 - /bin/bash
Binaries:
  Node: 25.2.1 - /opt/homebrew/bin/node
  npm: 11.6.2 - /opt/homebrew/bin/npm
npmPackages:
  @cloudflare/vite-plugin: ^1.35.0 => 1.35.0
  @cloudflare/workers-types: ^4.20260430.1 => 4.20260502.1
  wrangler: ^4.87.0 => 4.87.0

Please provide a link to a minimal reproduction

No public repro repo yet. Minimal inline repro:

  1. Create a Worker app using @cloudflare/vite-plugin
  2. Set dev.host in wrangler.jsonc, for example:
    {
      "name": "repro",
      "main": "./src/index.ts",
      "compatibility_date": "2025-06-17",
      "dev": {
        "host": "repro.example.workers.dev"
      }
    }
  3. In the Worker, add an endpoint that fetches https://httpbin.org/headers and returns the response body
  4. Run vite dev
  5. Hit that endpoint

Describe the Bug

vite dev drops the zone value before handing the worker to Miniflare, so outbound subrequests get CF-Worker: <worker-name>.example.com even when dev.host is configured.

In my case this breaks Apple WeatherKit locally because Apple rejects CF-Worker: trmnl.example.com with 403 Forbidden.

I believe this regressed as part of the CF-Worker header support added in PR #12186.

Observed:

  • under vite dev, outbound requests include CF-Worker: <worker-name>.example.com
  • WeatherKit returns 403 Forbidden

Expected:

  • vite dev should propagate the configured host/zone so outbound requests include the configured dev.host (or equivalent route-derived zone), matching wrangler dev --local

What I verified while tracing this:

  • wrangler dev --local does work once the generated config is current
  • under wrangler dev --local, outbound requests include the configured host in CF-Worker
  • under vite dev, the Vite plugin has the right values before calling Wrangler:
    • worker.config.dev.host is set
    • worker.config.routes is set
  • inside wrangler.unstable_getMiniflareWorkerOptions(...), those values are still present on config
  • but the returned workerOptions has no zone, so Miniflare falls back to ${workerName}.example.com

This looks like the drop point:

  • packages/vite-plugin-cloudflare/src/miniflare-options.ts calls wrangler.unstable_getMiniflareWorkerOptions(...)
  • packages/wrangler/src/api/integrations/platform/index.ts builds workerOptions but does not include zone
  • packages/miniflare/src/plugins/core/index.ts then falls back to ${workerName}.example.com

A local workaround that fixes vite dev for me is to inject zone: worker.config.dev?.host into the worker object constructed in packages/vite-plugin-cloudflare/src/miniflare-options.ts after spreading workerOptions.

Please provide any relevant error logs

From a local probe of the outgoing headers under vite dev:

{
  "headers": {
    "Cf-Worker": "repro.example.com",
    "Host": "httpbin.org"
  }
}

From the same probe under wrangler dev --local with current generated config:

{
  "headers": {
    "Cf-Worker": "repro.example.workers.dev",
    "Host": "httpbin.org"
  }
}

Metadata

Metadata

Assignees

Labels

package:vite-pluginRelating to the `@cloudflare/vite-plugin` package

Type

Fields

No fields configured for Bug.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions