Site config

A site is configured in site.config.ts at the project root. It creates a Site and exports it as the default:

// site.config.ts
import { Site } from "@torpor/build";

const site = new Site();

await site.addRouteFolder("./src/routes");

export default site;

Routes

addRouteFolder adds every route file in a folder (see Routing). For small sites, routes can also be added in code with addRoute, which takes a path and any combination of page, pageServer, server, layout, hookServer and error options:

site.addRoute("/", {
	page: "./src/views/Home.torp",
	pageServer: { actions: { set: async ({ request }) => ok() } },
});

site.addRoute("/api/time", {
	server: { get: async () => ok({ time: Date.now() }) },
});

addRouteFile adds a single file route, and routes can be grouped with their own hooks by passing a subFolder.

Options

  • site.adapter — the deployment adapter, e.g. @torpor/adapter-node, @torpor/adapter-cloudflare or @torpor/adapter-electron. When not set, one is resolved from the environment or installed packages
  • site.basePath — the path the site is mounted under, e.g. "/app". Incoming requests without it aren't served, and everything the framework generates (links, form actions, redirects) gets it added automatically
  • site.output — the build output folder, relative to the project root (or absolute). Defaults to "dist". Set it when several apps build from the same source root, so they don't clobber each other's output
  • site.env — a Standard Schema (zod, valibot, arktype, etc) that validates the server environment, throwing with the schema's issues when env() reads a missing or invalid key. See Environment
  • site.prerender — a default for rendering routes to static HTML at build time: a boolean, or a map of paths to flags for large chunks of the site (e.g. { "/blog/**": true }). See Prerendering
  • site.origin — the site's absolute origin (e.g. "https://example.com"), used by the build-time sitemap from site.sitemap. See Discovery
  • site.middleware — global middleware, run for every request before routing. Server endpoints also take middleware arrays for route-scoped guards
  • site.plugins — site plugins, which can add routes and framework-level functionality when the site config is loaded or the server starts up, e.g. openApi()
  • site.inputs — extra file paths to include in the compiled build output; files ending with server.ts only end up in the server build
  • site.vitePlugins and site.viteConfig — extra Vite plugins, and Vite config options to merge into the client and server builds