About · Light Switch

Built to be
understood.

Most renderers ask you to learn a framework before you can ship a page. Light Switch asks you to learn one request. Follow it from the browser to the finished HTML and you know the whole system — this page walks that path, starting gently and ending in the machinery.

package crr_renderer image crr-renderer port 8787 this page route /about/ → template about
The story

A renderer that survived
its own website.

Light Switch — package name crr_renderer, the Cloud Run Renderer — began life powering a production site. When that site was retired, the product pages were stripped away and what remained was the part worth keeping: a small, proven engine that had already carried real traffic, real APIs and real experiments. One route survived the clean-out. These pages are the engine, dressed up to explain itself.

Origin
🏭

Battle-tested, then distilled

Storage proxying was ported from renderer_different; leftovers like an force-variant host still sit in comments like fossils. What is here earned its place in production.

Philosophy
💡

Named after a light switch

On, off. Request, page. The name is the spec: the simplest possible interface hiding wiring you only open up when you need to.

Today
🧪

A clean shelf to build from

Endpoints, experiments and storage sit configured-off, ready. Clone it, run docker-compose up, and you start from a working renderer — not a blank repo.

Principles

Four ideas run
the whole show.

This list is not typed into the HTML — a data loader (utils/hooks/data_loaders/about.js) hands it to the template, which loops over it. You are looking at the framework feeding its own documentation.

01

Flip the switch, ship the page

The renderer has one job: turn a request into HTML as directly as possible. Every feature — routing, data, experiments — exists only because a real page needed it.

02

Convention over ceremony

A page is a template file, a line in a registry, and a route. Content is a Markdown file. A dataset is a CSV. If you can name the file, you can find the behaviour.

03

The data object is the contract

Templates never fetch, guess, or compute. Everything a page may need is assembled upstream into one inspectable object — and ?api=true shows it to you verbatim.

04

Simple surface, honest depths

YAML and Mustache on the surface; regex routing, encrypted API payloads and deterministic hashing underneath. Start in minutes, go as deep as the problem demands.

Run it

Two ways in.
Both take a minute.

Docker — the intended path
$ docker-compose up --build # → http://localhost:8787 # injects PORT · API_VIEW_FLAG=true # STAGE=false · KRYPTOPASS
Host — for hacking on the renderer itself
$ cp example.env .env $ npm run dev # nodemon server/server.js $ npm run gulp # Less + JS watcher
Env

API_VIEW_FLAG

When true, ENVIRONMENT follows config.js environment_switch (development) and ?api=true exposes the data object. Otherwise the environment is production and the inspector stays shut.

Env

KRYPTOPASS

Only used to AES-decrypt text/plain API bodies. Leave it unset and the server simply logs a warning and starts anyway — it is a key, not a gate.

Env

STAGE

Basic auth (screamingfrog / screaming) arms only when STAGE is the exact string "true" — a staging seatbelt in authorizeHandler, invisible everywhere else.

Proof by construction

This page was added
in four steps.

No new server code, no build configuration. The same four steps add the next page — and the one after that.

STEP 01

Write the template

Create src/templates/about.html — YAML front matter above a --yaml-- line, Mustache and shared partials below.

STEP 02

Register it

Add one import and one key in src/templates/index.js. The key is the name routes will reference.

STEP 03

Add the route

In config.js: { "host": "", "path": "/about/?", "template": "about" }. Named regex groups become URL params automatically.

STEP 04

Load its data

Optional: add utils/hooks/data_loaders/about.js and register it in apiDataTrx.js — exactly how this page feeds its own sections.

The deep end · for engineers

Now the
complexities.

Everything below is live behaviour in this codebase, in pipeline order: authorizeHandler → routeHandler → bucketTestingHandler → dataHandler → contentHandler → variationHandler → templateHandler → loggingHandler → renderRoute, with errorHandler rendering error.html whenever anything throws. Registration order in server/app.js puts compression, cookies and Cloudflare-header capture first, storage routes (when enabled) ahead of the /_/ static handler, a JSON-404 for /favicon.ico, a 30-second timeout, and the POST /seo-tracking/ beacon ahead of the catch-all.

hosts

config.js hosts is a hard allow-list (localhost, www.localhost, 127.0.0.1 here). An unlisted hostname 404s before routing — even for routes with host: "". A non-empty route host is a regex, e.g. "www.example.com|staging.example.com", for multi-brand serving from one deploy.

Allow-list

path regex

Route paths are full-path regex anchored with ^…$. Named groups (?<slug>[a-z0-9-]+) become data.urlprops.params — an array of single-key objects the template and loaders can read. template: "statusChange" skips rendering entirely and throws route.status (410 Gone, say).

Routing

endpoints

A route opts into data with "endpoint": "<key>". The fetch URL is endpoints[key][ENVIRONMENT] + "/" + data_version + path — the browser path and API path are 1:1. Endpoint headers merge with route headers (route wins). ENVIRONMENT follows config environment_switch only while API_VIEW_FLAG=true; otherwise it is production.

Data APIs

KRYPTOPASS

A text/plain API body is AES-decrypted before JSON.parse — either iv:ciphertext (SHA-256 key, CBC) or legacy CryptoJS format. Unset KRYPTOPASS only logs a warning; the server still starts. A non-200 upstream becomes an HttpError, except 404, which hands the body to the error page as commonNames — "possible matches" — and falls through.

Encryption

data loaders

utils/hooks/apiDataTrx.js maps pagetype → loader list. Loaders run in order, mutate data in place, and may set data.recordCount for logging. HttpError from a loader always reaches errorHandler; other errors are logged and swallowed unless the template joins STRICT_TEMPLATES. Mustache lambda helpers (dates, case, slugs, state lookup, formatCount, ifEquals…) attach before loaders run.

Hooks

variations

Cookie variations assign control/variant randomly, persist 30 days in a sha256(path) cookie, and share one cookie across route_groups with identical path strings. Bucket tests skip cookies entirely: hash(path) % templates.length is stable per URL. template_rules run last — first matching when wins, e.g. singleRecord when data.persons.length === 1.

Experiments

storage

Ported from renderer_different and switched off until paths.storageFolder points at a public bucket. assetHandler proxies /_/storage/…, downloadHandler serves flat, sanitised PDF filenames from /downloads/. Traversal (.. , backslashes, escaping URLs) is rejected and an upstream 403 reads as 404.

Idle, ready

logging

loggingHandler writes a structured log on response finish (skipping assets and health checks), the head partial pushes variation/bucket payloads to dataLayer, and the client logger.js keeps a 2-year visitorid, first/last-touch attribution, and beacons actions to POST /seo-tracking/ (204). The error handler renders error.html — and arms a 404 beacon.

Observability
request order — server/app.js (catch-all)
app.all("*app", authorizeHandler, // STAGE basic-auth routeHandler, // redirects → host/path bucketTestingHandler, getData, // endpoint + loaders getContent, // markdown + tables variationHandler, // cookie split templateHandler, // template_rules loggingHandler, renderRoute)
debug any page — the data object
GET /about/?api=true → { HOST, _config, assetsDate,  urlprops: { pagetype: "about",  params: null },  isMobile, isDev, states,  cloudFlareHeaders, principles… } // local only: API_VIEW_FLAG=true
Questions

Asked at every
handoff.

Yes for templates, partials, Markdown and tables — those files are read once at process start and cached. In local dev nodemon (npm run dev) restarts for you on any file change. Less and client JS are handled separately by the running Gulp watcher, which also bumps the CSSDATE/JSDATE cache-busters in server/globals.js.

Run locally with API_VIEW_FLAG=true (the default in Docker) and append ?api=true to any URL. You get the full data object as JSON — API payload, urlprops, states, Cloudflare headers and loader additions — minus the Mustache lambda functions.

A non-200 upstream becomes an HttpError and renders the error template with the right status — except a 404, whose body is treated as suggested matches (commonNames) and shown on the error page. If the chosen template is listed in 404pagetypes and the API returned nothing, the response is a clean 404.

Use a cookie variation for a classic visitor-level A/B test (same person, same variant, 30 days). Use a bucket test when the URL itself should decide — every visit to that URL, from anyone, renders the same variant because it is hashed from the path. template_rules sit above both when the data, not the visitor, should decide.

Not yet. It is fully ported and tested in sibling renderers, but paths.storageFolder is "" in config.js, so neither /_/storage/ nor /downloads/ is mounted. Point it at a public bucket URL and both routes switch on — they are registered before the static asset handler precisely so they win over /_/.

Because the renderer pushes complexity upstream into data loaders, where it is testable JavaScript, and keeps templates logic-light: variables, sections, partials and a small set of lambda helpers. Writers and designers can edit HTML safely; engineers keep the sharp tools in code.

The switch is on

You have read the renderer.
Now render something.

Add a template, register it, route it, load its data. Four steps — the same four that built this page — and Light Switch does the rest.