Skip to content
betterstack-alchemyUnofficial

Cloud.Website.StaticSite

Kind ResourceType id BetterStack.Cloud.Website.StaticSiteSource src/Cloud/Website/StaticSite.tsLive test gated Lifecycle test runs against the offline mock; a live run exists but is gated behind BETTERSTACK_TEST_CLOUD_SERVER=1 because it runs live only in the shared server suite (test/Cloud/live), one billed server per run (test/Cloud/live/SharedServer.live.test.ts).

A static site on Better Stack Cloud: a build command’s output directory served by a small generated Node server (GET assets with their content type, cache-control: no-cache, GET /health, optional SPA fallback or 404 page) running as one Cloud.Service on port 3000. Use it for Hugo, Zola, Eleventy, a hand-written public/ directory, or any custom pipeline. The port of Hetzner.Website.StaticSite.

What a deploy does: runs command in cwd (Command.Build, skipped when the inputs are unchanged; destroying the site deletes outdir, so it must be build output, never your sources), writes the serve entry serve-node.mjs next to outdir (the same generator the framework Node targets use, from @alchemy.run/frontend-frameworks/core, which must be installed), then copies the entry and outdir over SSH as they are (prebuilt: true, no bundling) and starts the unit, gated on /health. Unchanged output is a no-op with no SSH; any changed file re-copies and restarts the unit.

Server and cost. Without server, the composite creates a billable Cloud.Server: AM1 (the smallest type) on ubuntu-26-04, term monthly. Pass server to put the site on a server you already pay for; one website per server (they all listen on 3000). With a Cloud.Firewall on that server, pass it as firewall and the composite opens port 3000.

Domain and TLS. Better Stack has no DNS product: domain takes a DNS adapter of another provider ({ name, dns: Cloudflare.DNS.Adapter() }) and publishes an A record at the server’s IPv4; the URL becomes http://{domain}:3000. The site itself speaks plain HTTP (as on Hetzner). For HTTPS on 443, put a Cloud.LoadBalancer in front with a Cloud.LoadBalancerService (protocol: "https", listenPort: 443, destinationPort: 3000, certificateIds: [certificate.id] from a managed Cloud.Certificate), a Cloud.LoadBalancerTarget on the server and a health check on /health — a billable load balancer, so it is a recipe, not a prop.

CDN. None. Better Stack’s object cache (Cloud.ObjectCache) is an S3-compatible cache in front of buckets at another storage provider, read by S3 clients that sign with SigV4; its docs state no anonymous browser access and no way to front an HTTP origin such as this server, so it cannot serve as the site’s CDN. The assets are served by the unit itself.

Verified live (2026-12-01): served from an existing server (server + firewall) on port 3000 with the expected content types and cache-control. The other Cloud.Website.* frameworks are verified offline only.

Deploying a Hugo site

const site = yield* BetterStack.Cloud.Website.StaticSite("Blog", {
command: "hugo --minify",
outdir: "public",
});

On a server you already have, behind its firewall

const site = yield* BetterStack.Cloud.Website.StaticSite("Site", {
command: "npm run build",
outdir: "dist",
server,
firewall,
});

SPA-style routing

const site = yield* BetterStack.Cloud.Website.StaticSite("App", {
command: "npm run build",
outdir: "dist",
spa: true,
});

Publish the record in Cloudflare

// Requires Cloudflare.providers() in the stack.
const site = yield* BetterStack.Cloud.Website.StaticSite("Blog", {
command: "hugo --minify",
outdir: "public",
domain: { name: "blog.example.com", dns: Cloudflare.DNS.Adapter() },
});

External Dev Server

const site = yield* BetterStack.Cloud.Website.StaticSite("App", {
command: "npm run build",
outdir: "dist",
dev: { command: "npm run dev" },
});

command string required

Command that produces the site (e.g. hugo --minify), split on whitespace and run without a shell.

outdir string required

Directory the command writes, relative to cwd. It is build output: destroying the site deletes it (Command.Build removes its outdir), so never point it at hand-written sources.

cwd string

Working directory for command. Default: process.cwd().

dev { command: string; cwd?: string | undefined; env?: Record<string, string | Redacted<string>> | undefined; url?: string | undefined; }

Local dev configuration. When alchemy dev runs, the build command is skipped and command is spawned as a long-lived child. Without dev, the site is still built and served locally (no cloud Service).

domain string | { name: string; dns?: DnsConfig<string> | undefined; }

Optional custom domain pointed at the server's public IPv4 through a DNS adapter: { name: "app.example.com", dns: Cloudflare.DNS.Adapter() }. The site url becomes http://{domain}:3000 (no TLS on the Service; for HTTPS put a Cloud.LoadBalancer with a Cloud.Certificate in front). A plain string fails with WebsiteDomainError: Better Stack has no DNS zone to create the record in.

env Record<string, string | Redacted<string> | Output<string | undefined, any>>

Process environment for the hosted unit (and the local framework dev server). Accepts Outputs (e.g. VITE_API_URL: api.url) and Redacted secrets: those reach the unit at runtime only — written in clear text solely to its env file on the server (mode 600), shown (redacted) in the plan, kept inside the state store's redaction marker, and NOT passed to the deployed build (only plain values are).

errorPage string

Serve this page with a real 404 status for requests that match no file. Mutually exclusive with spa.

firewall Firewall | Effect<Firewall, never, Providers>

A Cloud.Firewall the server has attached. A firewall admits only what its rules allow, so the composite adds an inbound TCP rule for port 3000 from anywhere (FirewallRule with logical id Port). Leave it out for a server without a firewall (every port is reachable).

memo boolean | MemoOptions

Controls which files are hashed to decide whether the build re-runs. Default: true.

server Server | Effect<Server, never, Providers>

Server the site's Service runs on: a Cloud.Server or an Effect that produces one. The server must carry Alchemy's deploy key (the default bootstrap: true). When omitted, the composite creates a billable server: AM1 (the smallest type) on ubuntu-26-04, term monthly, in the credentials' availability zone. Several sites (and Services) can share one server: each is its own systemd unit, but they all listen on port 3000, so only one website fits per server.

spa boolean

Answer misses with the index page (200) instead of a 404 so client-side routes deep-link correctly. Mutually exclusive with errorPage.

tags Record<string, string>

Your own tags, set as the metadata of the server the composite creates (at most 10). Ignored when server is given.