diff --git a/docs/contributing/setup-manifest.md b/docs/contributing/setup-manifest.md index f31955d62c..9f8863f82e 100644 --- a/docs/contributing/setup-manifest.md +++ b/docs/contributing/setup-manifest.md @@ -80,13 +80,17 @@ This project uses the following resources: `PACKAGE_APP_BASE_URL` is set without `APP_BASE_URL` rather than publishing a partial set. Any domain attached out-of-band must be added here before the next deploy, or that deploy will remove it. - - The route deliberately does **not** live in - `packages/worker/wrangler.jsonc`: `npm run dev` runs `wrangler dev` against - the **production** environment, and Wrangler resolves local request URLs - against the first configured route, so a committed route makes every local - request arrive as `http://kodyapps.dev/...` — canonical URLs, OAuth resource - metadata, and login redirects then point at the production domain from - localhost. + - Publishing routes also flips `workers_dev` to `false`, which silently drops + the `..workers.dev` trigger (Cloudflare then answers that + hostname with error 1042). The generator sets `workers_dev: true` alongside + the routes so that backup access path — which MCP clients may point at, and + which the deploy's URL fallback looks for — survives. + - The routes deliberately do **not** live in `packages/worker/wrangler.jsonc`: + `npm run dev` runs `wrangler dev` against the **production** environment, + and Wrangler resolves local request URLs against the first configured route, + so a committed route makes every local request arrive as + `http://kodyapps.dev/...` — canonical URLs, OAuth resource metadata, and + login redirects then point at the production domain from localhost. - The app origin (`heykody.dev`) stays attached out-of-band; Wrangler does not remove routes that the config omits. - Attaching a custom domain needs a deploy token with edit access to the diff --git a/tools/ci/resource-utils.node.test.ts b/tools/ci/resource-utils.node.test.ts index c87dbf5936..9240016646 100644 --- a/tools/ci/resource-utils.node.test.ts +++ b/tools/ci/resource-utils.node.test.ts @@ -68,6 +68,7 @@ test('writeGeneratedWranglerConfig preserves migrations and copies environment a assets?: { run_worker_first?: Array } r2_buckets?: Array<{ binding: string; bucket_name: string }> routes?: Array<{ pattern: string; custom_domain?: boolean }> + workers_dev?: boolean vars?: Record } } @@ -114,6 +115,8 @@ test('writeGeneratedWranglerConfig preserves migrations and copies environment a custom_domain: true, }, ]) + // Publishing routes otherwise drops the workers.dev trigger. + expect(productionConfig.env?.production?.workers_dev).toBe(true) const previewOutPath = path.join(tempDir, 'wrangler-preview.generated.json') await writeGeneratedWranglerConfig({ @@ -150,8 +153,9 @@ test('writeGeneratedWranglerConfig preserves migrations and copies environment a { binding: 'EMAIL_BLOBS', bucket_name: 'kody-pr-123-email-blobs' }, ]) // Preview serves package apps inline on its own origin, so it publishes no - // routes and keeps whatever domains are attached out-of-band. + // routes and keeps whatever domains and triggers it already had. expect(previewConfig.env?.preview?.routes).toBeUndefined() + expect(previewConfig.env?.preview?.workers_dev).toBeUndefined() expect(consoleError).toHaveBeenCalledWith( `Wrote generated Wrangler config: ${previewOutPath}`, ) diff --git a/tools/ci/resource-utils.ts b/tools/ci/resource-utils.ts index f52e415270..5daed3a560 100644 --- a/tools/ci/resource-utils.ts +++ b/tools/ci/resource-utils.ts @@ -765,8 +765,13 @@ function addPackageAppCustomDomainRoute(input: { .filter((hostname) => !routedHostnames.has(hostname)) .map((pattern) => ({ pattern, custom_domain: true })), ] + // Publishing routes flips `workers_dev` to false, which removed the + // `..workers.dev` trigger the deploy previously kept as a + // backup access path (and that MCP clients may be pointed at). Ask for it + // explicitly so adding a custom domain does not silently take it away. + input.targetEnv.workers_dev = true console.error( - `Custom domain routes: ${appHostname} (APP_BASE_URL), ${packageAppHostname} (PACKAGE_APP_BASE_URL)`, + `Custom domain routes: ${appHostname} (APP_BASE_URL), ${packageAppHostname} (PACKAGE_APP_BASE_URL); workers.dev trigger kept`, ) }