From bafa5ac4d466329b3c01dbecf9561a404e70ae02 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Mon, 6 Jun 2022 16:40:20 +0100 Subject: [PATCH] fix: use worker name as a script ID when generating a preview session (#1192) When generating a preview session on the edge with `wrangler dev`, for a zoned worker we were using a random id as the script ID. This would make the backend not associate the dev session with any resources that were otherwise assigned to the script (specifically for secrets, but other stuff as well) The fix is simply to use the worker name (when available) as the script ID. Fixes https://github.com/cloudflare/wrangler2/issues/1003 Fixes https://github.com/cloudflare/wrangler2/issues/1172 --- .changeset/eleven-games-mate.md | 10 ++++++++++ packages/wrangler/src/create-worker-preview.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/eleven-games-mate.md diff --git a/.changeset/eleven-games-mate.md b/.changeset/eleven-games-mate.md new file mode 100644 index 000000000000..9d68df2dc552 --- /dev/null +++ b/.changeset/eleven-games-mate.md @@ -0,0 +1,10 @@ +--- +"wrangler": patch +--- + +fix: use worker name as a script ID when generating a preview session + +When generating a preview session on the edge with `wrangler dev`, for a zoned worker we were using a random id as the script ID. This would make the backend not associate the dev session with any resources that were otherwise assigned to the script (specifically for secrets, but other stuff as well) The fix is simply to use the worker name (when available) as the script ID. + +Fixes https://github.com/cloudflare/wrangler2/issues/1003 +Fixes https://github.com/cloudflare/wrangler2/issues/1172 diff --git a/packages/wrangler/src/create-worker-preview.ts b/packages/wrangler/src/create-worker-preview.ts index 5addf5b3b982..28eb301bd166 100644 --- a/packages/wrangler/src/create-worker-preview.ts +++ b/packages/wrangler/src/create-worker-preview.ts @@ -111,7 +111,7 @@ async function createPreviewToken( ); const { accountId } = account; - const scriptId = ctx.zone ? randomId() : worker.name || host.split(".")[0]; + const scriptId = worker.name || (ctx.zone ? randomId() : host.split(".")[0]); const url = ctx.env && !ctx.legacyEnv ? `/accounts/${accountId}/workers/services/${scriptId}/environments/${ctx.env}/edge-preview`