A route says where
A line in config.js pairs a URL pattern with a template: / → home, /about/ → about. Patterns are regex, so /(?<state>\w+)/ quietly hands the page a state value to work with.
Light Switch is a lightweight HTML & Mustache renderer that turns a request into a finished page in one clean pass — route, data, template, done. No heavy framework between your content and the browser. No build step between an idea and a live URL.
$ docker-compose up --build → http://localhost:8787
That is the whole mental model. If you can hold these three ideas, you already understand Light Switch — everything else is refinement.
A line in config.js pairs a URL pattern with a template: / → home, /about/ → about. Patterns are regex, so /(?<state>\w+)/ quietly hands the page a state value to work with.
Before anything renders, the framework assembles one data object: API results, YAML typed at the top of the template, Markdown articles, CSV tables, even the visitor's Cloudflare geo headers. One place, everything a page could need.
Plain HTML with Mustache's friendly curly braces — {{title}} drops a value in, {{> HEADER}} reuses a shared partial. Designers edit it safely; nothing in it can crash the server.
Every request walks the same middleware pipeline registered in server/app.js. Click each stage — this is the exact journey from browser to rendered HTML, in order.
Before any route matches, the request is checked against redirects.json. Patterns are full-path regex (301 or 302), the query string is preserved, and a hit short-circuits everything downstream. Try it: /example-redirect/ lands right back here.
Six systems do the heavy lifting, each switched on by a line of config — and each idle until you ask for it. This very page is rendered by them: its stats, pipeline and cards are fed by a data loader, not hand-typed HTML.
Host and path are plain regex in config.js. Named capture groups flow straight into the page data, so /california/ and /articles/my-post/ need no router code at all.
API payload, YAML front matter, Markdown, CSV tables, states and Cloudflare geo — merged into a single object your template simply reads from. What you see at ?api=true is what the template got.
Cookie variations for classic A/B splits and deterministic bucket tests for URL-stable variants. Both report into dataLayer and the /seo-tracking/ beacon automatically.
Drop a .md file in src/markdown, register it, and it renders as HTML in any template. CSVs become iterable tables the same way. No deploy pipeline for a comma.
Above-the-fold CSS is inlined in the head, HTML whitespace is collapsed, assets are minified by Gulp with cache-busted URLs, and static files carry 30-day cache headers.
Host allow-list, 30-second timeout, staging basic-auth, AES-decrypted API bodies, path-traversal-proof storage proxying, and an error template that renders instead of leaking a stack.
Pages stop being tickets and start being files. The path from idea to live URL is short, visible, and hard to break.
Under the calm surface: a strict middleware pipeline with deterministic behaviour you can reason about — and debug with one query param.
data.urlprops.params.apiDataTrx) that mutate one inspectable data object in order.template_rules — layered in that order.Adding a page is declaring intent in three small places. This site added its About page in exactly these steps — the files below are real.
// "" host = any allow-listed host { "host": "", "path": "/about/?", "template": "about" // "endpoint": "api_base_url", ← opt into data // "variations": ["aboutAlt"], ← opt into a test }
title: "About — Light Switch" h1: "Built to be understood." --yaml-- <h1>{{h1}}</h1> {{#principles}} <!-- loop loader data --> <h3>{{title}}</h3> {{/principles}}
Principles, the full middleware anatomy, encrypted endpoints, experiment layering, storage proxying — and the four steps to add your own page, documented on the page that used them.
Read the About page →