diff --git a/.changeset/deployed-url-custom-domain.md b/.changeset/deployed-url-custom-domain.md new file mode 100644 index 00000000..8a9070c5 --- /dev/null +++ b/.changeset/deployed-url-custom-domain.md @@ -0,0 +1,4 @@ +--- +"@cloudhal/cli": patch +--- +`cloudhal deploy` no longer fails with "Invalid URL" after deploying a site with a custom domain from a fresh checkout (Workers Builds): wrangler lists the domain as `example.com (custom domain)`, and the note is now dropped before the address is used. diff --git a/packages/cli/src/cloudflare/wrangler.ts b/packages/cli/src/cloudflare/wrangler.ts index a044dff2..8d86486e 100644 --- a/packages/cli/src/cloudflare/wrangler.ts +++ b/packages/cli/src/cloudflare/wrangler.ts @@ -136,8 +136,13 @@ export async function must( /** URLs of a deployed Worker from wrangler's structured output. */ export function deployedUrls(records: Record[]): string[] { - return records - .filter((r) => r.type === "deploy") - .flatMap((r) => (Array.isArray(r.targets) ? (r.targets as string[]) : [])) - .map((t) => (t.startsWith("http") ? t : `https://${t}`)); + return ( + records + .filter((r) => r.type === "deploy") + .flatMap((r) => (Array.isArray(r.targets) ? (r.targets as string[]) : [])) + // Wrangler lists custom domains as "cloudhal.com (custom domain)": keep the hostname only. + .map((t) => t.trim().split(/\s+/)[0] ?? "") + .filter(Boolean) + .map((t) => (t.startsWith("http") ? t : `https://${t}`)) + ); } diff --git a/packages/cli/test/deployed-urls.test.ts b/packages/cli/test/deployed-urls.test.ts new file mode 100644 index 00000000..45b39378 --- /dev/null +++ b/packages/cli/test/deployed-urls.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from "vitest"; +import { deployedUrls } from "../src/cloudflare/wrangler.ts"; + +describe("deployedUrls", () => { + it("turns wrangler's deploy targets into URLs", () => { + const records = [ + { type: "wrangler-session" }, + { + type: "deploy", + targets: ["cloudhal-com-admin.example.workers.dev", "https://x.example.com"], + }, + ]; + expect(deployedUrls(records)).toEqual([ + "https://cloudhal-com-admin.example.workers.dev", + "https://x.example.com", + ]); + }); + + it("keeps only the hostname of a custom domain target (a fresh CI checkout parses it)", () => { + const urls = deployedUrls([{ type: "deploy", targets: ["cloudhal.com (custom domain)"] }]); + expect(urls).toEqual(["https://cloudhal.com"]); + expect(new URL(urls[0] as string).hostname).toBe("cloudhal.com"); + }); +});