From 7d5296f6975edc53ecd47d826e3b8eefe34586cb Mon Sep 17 00:00:00 2001 From: "gp42-ops (GitHub)" <91820843+gp42-ops@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:03:09 +0200 Subject: [PATCH] feat: sites.create takes a kind for redirect hosts kind "redirect" creates a redirect host: a hostname on one of the organization's own custom domains that serves only redirect rules and takes no uploads. Site gains kind, and SiteKind is exported. --- README.md | 9 +++++++++ src/__tests__/sites.test.ts | 12 ++++++++++++ src/index.ts | 1 + src/types.ts | 15 +++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/README.md b/README.md index cd038b1..c153603 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,19 @@ const { siteId } = await client.sites.create({ domain: "us.hostsmith.link", }); +// Create a redirect host on one of your custom domains +const { siteId: hostId } = await client.sites.create({ + subdomain: "go", + domain: "example.com", + kind: "redirect", +}); + // Delete a site await client.sites.delete("site-id"); ``` +A redirect host (`kind: "redirect"`) serves only its [redirect rules](#redirects), set with `client.sites.redirects` as for a site. It takes no files: `deploy()` and `startUpload()` are refused with `RedirectHostHasNoFiles`. It needs one of your organization's own custom domains, so a shared domain is refused with `CustomDomainRequired`. Redirect hosts don't count toward the plan's site limit; an organization can have up to 50, and the next create is refused with `RedirectHostLimitReached`. Every site has a `kind`, `"site"` or `"redirect"`. + ### Domains ```ts diff --git a/src/__tests__/sites.test.ts b/src/__tests__/sites.test.ts index 5a328a2..1c3fb51 100644 --- a/src/__tests__/sites.test.ts +++ b/src/__tests__/sites.test.ts @@ -51,6 +51,18 @@ describe("SitesResource", () => { expect(http.post).toHaveBeenCalledWith("/v1/sites", params); }); + it("create() sends the kind of a redirect host", async () => { + const http = createMockHttp(); + http.post.mockResolvedValue({ siteId: "new-id" }); + const sites = new SitesResource(http); + await sites.create({ subdomain: "go", domain: "example.com", kind: "redirect" }); + expect(http.post).toHaveBeenCalledWith("/v1/sites", { + subdomain: "go", + domain: "example.com", + kind: "redirect", + }); + }); + it("delete() calls DELETE /v1/sites/", async () => { const http = createMockHttp(); http.delete.mockResolvedValue({ status: "DELETING" }); diff --git a/src/index.ts b/src/index.ts index b8e4a64..b826b4b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ export type { PartitionInfo, PartitionListResponse, Site, + SiteKind, SiteListResponse, SiteCreateParams, SiteCreateResponse, diff --git a/src/types.ts b/src/types.ts index 7ca22b7..e318409 100644 --- a/src/types.ts +++ b/src/types.ts @@ -45,12 +45,20 @@ export type HostsmithOptions = { userAgent?: string; }; +/** + * `"site"` serves files and redirect rules. `"redirect"` is a redirect host: + * it serves only redirect rules, on one of the organization's own custom + * domains, and takes no uploads. Fixed at creation. + */ +export type SiteKind = "site" | "redirect"; + export interface Site { id: string; subdomain: string; domain: string; /** Data residency / partition the site lives in. */ partition?: Partition; + kind?: SiteKind; siteStatus?: string; deployId?: string; storageUsed?: number; @@ -64,6 +72,13 @@ export interface SiteListResponse { export interface SiteCreateParams { subdomain?: string; domain: string; + /** + * Defaults to `"site"`. `"redirect"` creates a redirect host, refused with + * 409 `CustomDomainRequired` on a shared domain. Redirect hosts don't count + * toward the plan's site limit; past 50 per organization the create is + * refused with 403 `RedirectHostLimitReached`. + */ + kind?: SiteKind; } export interface SiteCreateResponse {