Testing a Web App Locally

You can build and test a web app entirely on your machine. Two things can answer for its Application Engine:

what answersuse it
The Developer Editionthe full Application Engine and PostgreSQL, on your machinefrom the first screen you build, to see exactly what production does before anything is live
The site as publisheda published site's own engine, on Uniwebto run your working copy against real data

Your foundation doesn't change between them. It talks to whichever one answers through @uniweb/sdk, and never names an address.


The Developer Edition

The Developer Edition is the Application Engine's edition for your machine: the full engine and its PostgreSQL database, licensed for development only and run in a container, with Apple's container on macOS 26 and later or with Docker. It is free and doesn't expire. Each project gets an engine of its own, so what you test is what production does: sign-up and its mail, permissions, public queries, compute functions, and payments in Stripe's test mode.

There are two steps, and the CLI runs them both:

uniweb create my-app --template <a solution template>   # the project, and its engine, started
cd my-app && npm install
uniweb dev                                              # registers your data schemas on the engine, and runs the site against it

create sees that the template's site asks for a backend service and has a blueprint.yml, and gives the project its engine:

  1. It picks what runs the engine: Apple's container where it runs, otherwise Docker (--container docker or --container apple on uniweb engine setup chooses). Then it signs you in to Uniweb in your browser if you aren't. The engine is made under your handle, and you accept its licence there.
  2. It starts the engine. The CLI stays signed in to Uniweb, where you publish.
  3. It names the engine in your site's $devBackend (see below).

The engine prints where its Admin App is and how to sign in as its owner. To add the engine to a project you already have, run uniweb engine setup in it.

uniweb dev then starts the engine if it is stopped. It registers your data schemas on the engine, with the engine's own key, when they change (uniweb engine register does that on its own), sends your blueprint.yml the first time, and serves your site against it. The engine takes the blueprint once, as a live engine does. After that, change a setting in the engine's Admin App, or start the engine over. uniweb engine status, start, stop and reset manage it (CLI reference).

You never sign in to the engine. The CLI stays signed in to Uniweb, and registering your data schemas on the engine is a registration, not a publish. When the site is ready, uniweb publish takes it live on Uniweb, as any site. Before you do, run uniweb engine reset --yes and check that the site still works. Your live site starts from blueprint.yml and your types, not from your local engine's test data.

uniweb dev against an engine on your machine

$devBackend takes an engine's address. uniweb dev then forwards every request for your site's backend service to that engine:

services:
  backend: true                          # in production, your host's
$devBackend: http://localhost:8080/api   # in `uniweb dev`, the engine at this address answers it

Write the whole address the engine's instructions give for its API. The page still asks its own dev server, which forwards each request, so the page talks to one origin and sign-in cookies behave as they do in production. uniweb dev then sends your foundation's own types in full, @/track as @acme/track, as a build does, because the engine holds them under those names. Register them with it first (uniweb register, signed in to it). Records come from your record files until you name the engine's records too (below).

If nothing answers at the address, the dev server says so with a 502 that names it.

Public records. An engine also serves the entries your blueprint.yml opens to visitors (publicQueries:). Name its records address beside its API, each address whole as the engine's instructions give it:

$devBackend:
  backend: http://localhost:8080/api
  records: http://localhost:8080/<the engine's records path>/{locale}

With records, uniweb dev acts as your site's host. Every query a page asks is answered from your record files and the engine's public entries together, merged the way a published site's records service merges them. Entries members created then show on a page next to the records in your files. If the engine doesn't answer, a page still gets your files' records. Your site's search keeps working from its local index.

Compute functions. When an integration calls one of your compute functions, the engine asks a runner for it. With $devBackend set to an address, uniweb dev is that runner. An engine set up with uniweb engine setup is already pointed at it: uniweb dev answers its calls on a port of their own: on 127.0.0.1, which an engine in Docker can reach, or, for an engine in Apple's container, on its network's gateway address, the only address of your machine a container reaches there. For an engine you set up yourself, choose a port, give the engine http://host.docker.internal:<port>/_compute as its functions address, and start uniweb dev with UNIWEB_FUNCTIONS_PORT=<port>.

Each call runs the function from your working copy, so an edit answers the next call with nothing registered again. It runs under the same rules as uniweb compute run. A call that takes more CPU than the platform allows is refused, as the platform refuses it. To have the runner check that each call is signed by your engine, set UNIWEB_FUNCTIONS_KEY to the engine's functions key before uniweb dev.


The site as published

Once a site is published, test against it:

uniweb publish             # once: the site goes live, with its own engine
uniweb dev --published     # your working copy, against the site as published

Your foundation and pages are the working copy's, with live reload. The site's services are the published site's: a member signs in to its real engine and may do what it allows, and a page shows the records its visitors see. The dev server reads the addresses from the published page and forwards each request, so the page talks to one origin, and sign-in cookies behave as they do on the published site. $devBackend is not used.

Under --published, uniweb dev sends your foundation's own types in full, @/track as @acme/track, as a build does, so the engine answers for the types it holds. A type you add reaches it when you publish again. Record files reach the page when you uniweb push them.

Public queries show here. Entries a blueprint.yml opens to visitors who are not signed in (publicQueries:) reach a page through the site's records service, with records: true under services:. uniweb dev alone answers every query from your record files, so --published is where you see those entries before a visitor does.

⚠️ It is the published site's real data. What you do in the working copy reads and changes its members' entries, and uniweb dev --published says so when it starts. Against the Developer Edition, that data is your own.


See also