-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[wrangler] Preserve inferred zone in Miniflare worker options #13792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| Pass the local dev zone through `unstable_getMiniflareWorkerOptions` | ||
|
|
||
| When `@cloudflare/vite-plugin` asks Wrangler for Miniflare worker options, the returned object did not include the inferred `zone`. Miniflare then fell back to `<worker>.example.com` for the `CF-Worker` header, which differs from the `wrangler dev --local` path and can cause some upstreams to reject local subrequests. | ||
|
|
||
| This now forwards the same `dev.host` or inferred route host that Wrangler already uses in local dev so Vite-backed local development matches the existing local runtime behavior. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { describe, it } from "vitest"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { unstable_getMiniflareWorkerOptions } from "../api"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Config } from "@cloudflare/workers-utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function makeConfig( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| overrides: Partial<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dev: { host?: string; enable_containers?: boolean; container_engine?: string }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| route: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| routes: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }> = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: "test-worker", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| main: "./src/index.ts", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| compatibility_date: "2025-06-17", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| compatibility_flags: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rules: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queues: { producers: [], consumers: [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| migrations: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tail_consumers: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| streaming_tail_consumers: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| containers: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assets: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| define: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bindings: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| compliance_region: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dev: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ip: "localhost", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| port: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local_protocol: "http", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| upstream_protocol: "http", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enable_containers: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...overrides.dev, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...overrides, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as unknown as Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 In the The first test passes only by coincidence—
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe("unstable_getMiniflareWorkerOptions", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("forwards dev.host as the Miniflare zone", ({ expect }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { workerOptions } = unstable_getMiniflareWorkerOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| makeConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dev: { host: "example.workers.dev" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(workerOptions.zone).toBe("example.workers.dev"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("infers the Miniflare zone from the first route when dev.host is unset", ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { workerOptions } = unstable_getMiniflareWorkerOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| makeConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| routes: ["https://subdomain.example.com/*"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(workerOptions.zone).toBe("subdomain.example.com"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test (and probably some handling in the code) for the case where the host cannot be inferred? e.g.
routes: "*/*".