From e693fd0ef0f48702e5664bb7070c0a2723ef2cbd Mon Sep 17 00:00:00 2001 From: jalmonter <116984708+jalmonter@users.noreply.github.com> Date: Mon, 1 Dec 2025 21:04:48 -0400 Subject: [PATCH] fix(wrangler): show correct port in scheduled worker warning --- packages/wrangler/src/dev/miniflare/index.ts | 17 --------- packages/wrangler/src/dev/start-dev.ts | 39 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/packages/wrangler/src/dev/miniflare/index.ts b/packages/wrangler/src/dev/miniflare/index.ts index 59ac09c38d72..e99a96e3bb29 100644 --- a/packages/wrangler/src/dev/miniflare/index.ts +++ b/packages/wrangler/src/dev/miniflare/index.ts @@ -837,23 +837,6 @@ export async function buildMiniflareOptions( remoteProxyConnectionString: RemoteProxyConnectionString | undefined, onDevRegistryUpdate?: (registry: WorkerRegistry) => void ): Promise { - if (config.crons?.length && !config.testScheduled) { - const host = - config.initialIp === "0.0.0.0" || config.initialIp === "::" - ? "localhost" - : config.initialIp.includes(":") - ? `[${config.initialIp}]` - : config.initialIp; - const port = config.initialPort; - - logger.once.warn( - `Scheduled Workers are not automatically triggered during local development.\n` + - `To manually trigger a scheduled event, run:\n` + - ` curl "http://${host}:${port}/cdn-cgi/handler/scheduled"\n` + - `For more details, see https://developers.cloudflare.com/workers/configuration/cron-triggers/#test-cron-triggers-locally` - ); - } - const upstream = typeof config.localUpstream === "string" ? `${config.upstreamProtocol}://${config.localUpstream}` diff --git a/packages/wrangler/src/dev/start-dev.ts b/packages/wrangler/src/dev/start-dev.ts index 00964a93ec84..38531be91bc3 100644 --- a/packages/wrangler/src/dev/start-dev.ts +++ b/packages/wrangler/src/dev/start-dev.ts @@ -144,6 +144,15 @@ export async function startDev(args: StartDevOptions) { }) ); } + + // Print scheduled worker warning with the actual public URL + const allDevEnvs = [primaryDevEnv, ...secondary]; + const hasCrons = allDevEnvs.some( + (env) => + env.config.latestConfig?.triggers?.some((t) => t.type === "cron") ?? + false + ); + maybePrintScheduledWorkerWarning(hasCrons, !!args.testScheduled, url); }); return { @@ -346,3 +355,33 @@ function getResolvedSiteAssetPaths( args.siteExclude ); } + +/** + * Logs a warning about scheduled workers not being automatically triggered + * during local development. This should be called after the server is ready + * and the actual URL is known. + */ +function maybePrintScheduledWorkerWarning( + hasCrons: boolean, + testScheduled: boolean, + url: URL +): void { + if (!hasCrons || testScheduled) { + return; + } + + const host = + url.hostname === "0.0.0.0" || url.hostname === "::" + ? "localhost" + : url.hostname.includes(":") + ? `[${url.hostname}]` + : url.hostname; + const port = url.port; + + logger.once.warn( + `Scheduled Workers are not automatically triggered during local development.\n` + + `To manually trigger a scheduled event, run:\n` + + ` curl "http://${host}:${port}/cdn-cgi/handler/scheduled"\n` + + `For more details, see https://developers.cloudflare.com/workers/configuration/cron-triggers/#test-cron-triggers-locally` + ); +}