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-cloudflareor@torpor/adapter-electron. When not set, one is resolved from the environment or installed packagessite.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 automaticallysite.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 outputsite.env— a Standard Schema (zod, valibot, arktype, etc) that validates the server environment, throwing with the schema's issues whenenv()reads a missing or invalid key. See Environmentsite.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 Prerenderingsite.origin— the site's absolute origin (e.g."https://example.com"), used by the build-time sitemap fromsite.sitemap. See Discoverysite.middleware— global middleware, run for every request before routing. Server endpoints also takemiddlewarearrays for route-scoped guardssite.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 withserver.tsonly end up in the server buildsite.vitePluginsandsite.viteConfig— extra Vite plugins, and Vite config options to merge into the client and server builds