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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/sites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<encoded id>", async () => {
const http = createMockHttp();
http.delete.mockResolvedValue({ status: "DELETING" });
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type {
PartitionInfo,
PartitionListResponse,
Site,
SiteKind,
SiteListResponse,
SiteCreateParams,
SiteCreateResponse,
Expand Down
15 changes: 15 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Loading