Pages

Version 0.2.1 · Owners: @benallfree

Walkthrough for app owners: PocketOne apps. This page is the technical reference.

Server-rendered pages from a pb_pages folder, next to your pb_data. Each file becomes a route: .ets templates (EJS tags holding TypeScript) or TSX components, Markdown pages, layouts, .ts middleware and API routes, plus static files. Every file type is listed in File types. Page code runs in your app's JS VM, so it can use your data directly. Coming from the npm PocketPages package? See Moving from PocketPages 0.x.

Install · Configure · Use · Integrations · Example

Install

Pages is built into pocketone and on whenever a pb_pages folder exists next to pb_data. There's no switch: no folder, no pages. If the folder appears while the app runs, it starts serving it.

In your own Go build, register it after the JS VM (ext/jsvm), since page code runs there:

app := pocketbase.New()
jsvm.MustRegister(app, jsvm.Config{})   // page code runs in the app's JS VM
pages.MustRegister(app, pages.Config{}) // serves pb_pages next to pb_data
pages.RegisterCommand(app.RootCmd)      // the `pages create` and `pages starters` commands
app.Start()

The module is pocketone.dev/ext/pages. See example/main.go and Create your own extension.

Configure

Where the folder is

By default the folder is pb_pages next to pb_data. To use another one:

pocketone serve --pagesDir /path/to/pb_pages

A relative path resolves against the working directory, like --hooksDir. Its pocketone.yaml key is server.pages_dir.

+config.ts

Settings for your pages live in the folder itself, in pb_pages/+config.ts:

module.exports = {
  plugins: ['auth', 'realtime', 'datastar'],
  debug: false,
}
Key Default What it does
plugins [] Module names (a _private/ file, a node_modules package or a path, loaded with require), built-in plugins by name (auth, realtime, used when no module by that name is found), or custom plugins such as the add-ons. ETS and Markdown are always on.
debug false Detailed error pages and ctx.log.debug output even outside dev mode.

+config.ts runs on each page request. Unknown keys, names that are neither a module nor a built-in, or a plugin listed twice make every page answer with an error, and the reason goes to the log.

Dev mode

When the app runs in dev mode (--dev, or app.dev in pocketone.yaml), or +config.ts sets debug: true, you get detailed error pages with the file and line, and ctx.log.debug output. Otherwise visitors see a plain "Something went wrong" page and the full error goes to the log.

Use

Start from a starter kit

pocketone pages starters                         # list the kits
pocketone pages create myapp --starter daisyui-docs
cd myapp
pocketone serve --dir ./pb_data

Then open http://127.0.0.1:8090. pages create makes a new folder (it must not exist yet) with pb_pages and anything the kit needs beside it, such as pb_migrations. Without --starter you get minimal.

Kit What it is
minimal One page, no layout, no build step (the default).
mvp One page styled with MVP.css.
htmx A realtime chat and counter with htmx and the realtime plugin.
daisyui A navbar and drawer layout with Tailwind CSS and DaisyUI.
daisyui-docs A docs site from Markdown pages.
datastar A realtime chat with rooms, with Datastar.
auth Sign-up, sign-in (password, OTP, OAuth2, anonymous), email flows and a protected account page.

Write pages

Add or edit files in pb_pages and reload the browser; no restart is needed. A few examples of what the folder holds:

pb_pages/
  +config.ts         settings (above)
  +layout.ets        wraps every page
  +error.ets         your error page
  index.ets          /
  about.md           /about
  blog/[slug].ets    /blog/anything
  feeds/rss.ts       /feeds/rss, an endpoint (code, no template)
  _private/          partials, never served
  assets/app.css     a static file

The full contract is in SPEC.md: routes and precedence, middleware, page code and endpoints (.ts), ETS, partials, slots and layouts, Markdown, JSX and TSX, the ctx object, errors, the built-in auth and realtime plugins, custom plugins, add-ons and the changes from 0.x.

Highlights:

  • Static files get ETags and fingerprinted URLs through asset().
  • ctx.pb() is the bundled PocketBase JS SDK, called in-process as the visitor.
  • ctx.res.sse() streams server-sent events.
  • The auth plugin gives cookie sessions on PocketBase auth: password, OTP, anonymous, register, OAuth2 and the email flows (verification, password reset, email change). Accounts that need MFA (the collection's MFA is on and its rule matches) are refused by every pages sign-in method; pages has no second sign-in step yet.

What you'll see in the log

Problems in the folder (a bad file name, two files claiming the same route) are logged as pages: ... errors. If the site served cleanly before, pages keeps the previous routes until the folder builds cleanly again. Errors thrown by page code are logged in full.

Try the demo

example/ is a demo app with ETS, Markdown, TSX, auth, ctx.pb(), SSE and a JSON route. It has a live speed check at /speed.

cd example && go run . serve --dir=./pb_data

Commands and APIs

Generated from the pocketone binary and the contracts this extension provides.

Commands

What it adds to the pocketone binary (CLI reference):

Command
pocketone pages create <name> Create a folder with a starter kit (pb_pages and anything it needs)
pocketone pages starters List the starter kits

JavaScript API

What it adds to pb_hooks and page code: Pages JavaScript API.

Integrations

Works with

Extension How they fit
Multisite Pages is in the standard set, so every instance that runs PocketOne serves its own pb_pages (below).
Cache Compiled templates and modules go in the pages.compiled bucket (cache/v1, at most 32 MiB per app), keyed by content, so old versions are evicted instead of piling up. On a multisite host, instances serving the same files share one compiled copy. On a multisite host they also outlive an instance's restarts, since the cache belongs to the host. With the cache off, each JS VM compiles a file the first time it meets it.
Deploy pb_pages deploys with your other pb_* folders. pull doesn't fetch it by default; name it: pocketone pull prod pb_pages.

On a multisite host

Pages is a member of the standard set, so every instance serves its own <instance dir>/pb_pages, in the stock pocketone binary and in any host built on standard.New(). With an isolate runtime (Pocker), where instances are isolates in one process:

  • Each start of an instance's app gets its own route table, compiled templates (in its own pages.compiled bucket; identical files share one copy in the host's cache) and caches. An instance that sleeps drops them; nothing is shared between instances.
  • Page code runs in the instance's own sandboxed JS VM (jsvm), under its limits (execution time, memory, stack). include, require, ctx.resolve, ctx.res.file and asset never reach outside the instance's pb_pages; $os file access stays inside the instance folder. Tests: multiinstance_test.go.
  • An instance turns pages off in its settings with extensions: { pages: { enabled: false } }.

To try it: copy sites into multiinstance/example/pb_root/<name>.localhost/pb_pages, run go run ./multiinstance/example, and open http://<name>.localhost:8791.

Building on pages

  • Read the routes. pages.For(app) returns the service: Dir() is the folder, Table() the current route table, Errors() the problems from the last build.
  • Custom plugins. A factory in +config.ts can add to ctx, run on each request and transform rendered HTML (SPEC.md, section 9.2). Add-ons are built this way.

Example

example/main.go serves the demo in example/pb_pages: ETS, Markdown, TSX, auth, SSE and a JSON route. Run go run . serve --dir=./pb_data in example/ and open http://127.0.0.1:8090.

// Command example runs one PocketOne app that serves the demo in ./pb_pages (ETS templates and TypeScript, Markdown,
// a TSX page, auth, ctx.pb(), SSE, a JSON route, +404). ./pb_migrations creates a "notes" collection with three seed
// notes. From this folder:
//
//	go run . serve --dir=./pb_data
//
// Then open http://127.0.0.1:8090. Edit anything in pb_pages and reload; no restart needed.
//
// Logins (ext/devusers, local testing only): dashboard [email protected] / password, app user [email protected] /
// password.
package main

import (
	"log"

	"ganigeorgiev.com/pocketbase/pocketbase"
	"pocketone.dev/ext/devusers"
	"pocketone.dev/ext/jsvm"
	"pocketone.dev/ext/pages"
)

func main() {
	app := pocketbase.New()
	devusers.Register(app) // local testing: superuser [email protected] and user [email protected], password "password"

	jsvm.MustRegister(app, jsvm.Config{}) // page code runs in the app's JS VM
	pages.MustRegister(app, pages.Config{})

	if err := app.Start(); err != nil {
		log.Fatal(err)
	}
}

Speed

ext/pages against npm PocketPages 0.22.5 (the last 0.x release), serving the same starter kit pages: the 0.x kits in pb_hooks/pages on stock PocketBase 0.41.1, the v1 ports in pb_pages on the PocketOne binary.

Page Version Requests/s (50 concurrent) p50 p99 One at a time (median)
minimal / (EJS) npm 0.22.5 620 30 ms 670 ms 5.7 ms
ext/pages 10,850 1.8 ms 37 ms 0.2 ms
daisyui-docs /docs/overview (layouts, Markdown, partial) npm 0.22.5 580 28 ms 1.1 s 6.5 ms
ext/pages 6,510 4.1 ms 49 ms 0.4 ms
PocketBase's own /api/health (the ceiling) PocketOne 55,000 0.9 ms 2.4 ms 0.1 ms

About 17.5× more requests per second on the simple page and 11× on the docs page, with p99 latency 20× lower. Single requests take 0.2 to 0.4 ms instead of 6 ms. Memory after each run was similar (170 to 350 MB for both).

Why: 0.x parsed routes, ran EJS through a JS implementation and loaded its plugins inside the JS VM on every request. v1 builds the route table once, compiles each template once (EJS to JS in Go, Markdown with goldmark) and enters the JS VM once per request.

How it was measured (2026-11-11): Apple M1 Max, 10 cores, macOS 27, Go 1.27.4, hey against 127.0.0.1. Each server was warmed with 500 requests, then hey -z 10s -c 50 and hey -n 2000 -c 1; two rounds, which agreed within 5%. Every response was a 200 with the full page. The 0.x docs kit inlines about 6 KB of CSS into each page where v1 links app.css. Rerun it with bench/run.sh:

cp -R starters/daisyui-docs /tmp/v1-docs
pocketone superuser upsert [email protected] password --dir=/tmp/v1-docs/pb_data
bench/run.sh v1-docs 8804 /docs/overview "$(which pocketone)" /tmp/v1-docs

More in this folder

  • SPEC.md: the full Pages contract.
  • fixtures/: the request test cases (go test ./... runs them all).
  • starters/: the starter kits. addons/: JS add-ons such as Datastar.
  • docs/: the Pages docs, as pages, shown on pocketone.dev under this page. blog/: the Pages blog posts.

License

MIT