Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/deployed-url-custom-domain.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 9 additions & 4 deletions packages/cli/src/cloudflare/wrangler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ export async function must(

/** URLs of a deployed Worker from wrangler's structured output. */
export function deployedUrls(records: Record<string, unknown>[]): 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}`))
);
}
24 changes: 24 additions & 0 deletions packages/cli/test/deployed-urls.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
Loading