Pre-built code blocks

Turn a local app into a hosted one

The four things a local app needs before it can be hosted

For when the answer to “It runs on a server for other people, not just on my machine” is yes.

Derived from the Playground's own platform/ layer, which was built by taking a single-owner desktop tool toward hosted mode and finding the gaps the hard way.

One small house on the left and the same house repeated across a row of separately fenced plots on the right, with a gate and a glowing lamp at the entrance

Skip the rebuild

You do not write this one. It arrives in your project as ordinary source you can read, change and keep, with its audit record and its caveats beside it.

  1. Download the Playground. It is free and runs on your own machine.
  2. Start a new app and tick “It runs on a server for other people, not just on my machine”.
  3. This block is written in, along with anything else you ticked.

Download the Playground See the other blocks

The mistake it removes

The dangerous half of going hosted is not the features you add: it is the assumptions a local app made that stop being true. A local tool can assume one user, one machine, a writable disk and a trusted caller. Hosting breaks all four at once, and the failures are silent: the app keeps serving, just wrongly.

What the audit found

Named rather than summarized. The reasoning behind each one ships inside the block, so it travels with the code instead of living on a page you have to trust. A finding marked fixed was fixed after the audit ran; the verdict above is still the one the audit gave.

One more finding is written in the auditors' internal shorthand, so it is not listed here. The full text is in the report inside the block. It was fixed after the audit, in 91940b48a.

What you still have to do

A copied file cannot own your secrets, your host or your legal obligations. This is the part the block deliberately does not claim.

What lands in your project

node

  • node/cloud-kit.js

storeSeam() (local file OR database behind one resolver), readiness() (returns ready:false on an unwritable or hanging store, each write raced against a 2 s deadline, reason in the LOG not the body; it sets no status, so your /ready handler must answer 503 on ready:false), requireExposureConfig() (refuse to boot half-configured; an unset HOST counts as exposed, never as loopback), normalizeRequestPath()/requestPath() (ONE normalization of the request target: protocol-relative '//', repeated and trailing slashes, '.' and '..', percent-encoding decoded before any decision, and a REFUSAL, never a repair, for anything still abnormal: normalizeRequestPath() answers ok:false and requestPath() answers null, never '/'), pathAllowed() (deny is read before allow, both against that same normalized value, and a path on neither list is denied), and passcodeGate()/checkPasscode() (the per-request check: every request must carry 'Authorization: Bearer <passcode>', compared in constant time; an unset or weak passcode (too short, whitespace at either end, one character or one piece repeated, fewer than 6 different characters) refuses every request with 503 rather than letting it through; publicPaths such as '/ready' are exact normalized paths). The gate does nothing until you mount it: app.use(passcodeGate({ publicPaths: ['/health', '/ready'] })) before your routes.

sql

  • sql/cloud.sql

A minimal docs table for the database side of the seam. Same shape the local JSON store presents, so switching backends changes no calling code.

What you supply

Licensed MIT. It is a starting point, not a finished product.

Get it

Download the Playground See the other blocks

Nothing here is locked. The files are yours, in your folder, under a permissive license.

Questions

Is Turn a local app into a hosted one audited?
It was audited on 2026-09-29, and the verdict was not a clean pass. 8 findings have been fixed since then, and the verdict stands until the block is audited again.
What do I still have to do myself?
Mount the gate yourself, app.use(passcodeGate({ publicPaths: ['/health', '/ready'] })) before your routes, and serve the app over HTTPS so the Bearer passcode is not readable in transit. The gate, the passcode rules and the path checks ship and are tested (test/cloud-kit.test.mjs sections 4, 4b, 5, 6 and 7), but nothing is guarded until you mount it. One shared passcode is also not a user account: there is no per-user identity, no sign-in, no way to revoke one person short of changing AUTH_PASSCODE, and no limit on wrong guesses, so put a request limiter in front of the gate. Write deny rules in plain normalised form (/admin, not //admin or /admin/./), because rules are not normalised yet and an abnormal one never matches.
How do I get this code?
Download the Playground, start a new app, and tick “It runs on a server for other people, not just on my machine”. The block is written into your project as ordinary source you can read and edit.

All pre-built code blocks · Learn to build from zero · The coding guide