Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The web UI: pages and HTTP API

Source: https://github.com/developing-today/code/blob/main/pkgs/id/crates/id-web/src/routes.rs, https://github.com/developing-today/code/blob/main/pkgs/id/crates/id-web/src/security.rs, https://github.com/developing-today/code/blob/main/pkgs/id/crates/id-web/src/assets.rs, https://github.com/developing-today/code/blob/main/pkgs/id/web/package.json

The web UI is served by id serve --web. It lives in the id-web crate (crates/id-web) with a Bun + TypeScript frontend in pkgs/id/web. The main router has 54 distinct paths and 58 method bindings. A second, program-only router has 10 paths. Both are constructed in crates/id-web/src/lib.rs and routes.rs:

ConstructorSurface
create_routerThe main Explorer router below.
create_router_for_appThe Explorer router parameterised for one app.
create_program_routerThe program-only router: one listener pinned to one world.
Publication mountsA dynamic mount that rewrites a mounted path prefix into the program router inside the listener’s security layer. Publications are covered in serve and publications.

Serving defaults, from the CLI: --web is off by default, --port defaults to 3000, --bind defaults to 127.0.0.1. The repeatable --web-listen <IP:PORT> flag replaces the web_bindings list from the embedded defaults.json; see Configuration and environment. Multiple listeners can each be an Explorer listener, a program listener (program:<world>), or a document target.

Authentication and the security layer (WEB-15)

Every router is wrapped by security::protect in crates/id-web/src/security.rs. Four controls apply to every route, in this order:

  1. Bind. Loopback by default: the CLI --bind default is 127.0.0.1.
  2. Host allow-list. On loopback binds, the request Host must be localhost, 127.0.0.1 or ::1, plus any operator-configured extras. Other hosts are refused.
  3. Origin check. Any request carrying an Origin header must be same-origin: scheme, host and port must match, with no default-port expansion. The scheme counts as https only when the operator declared a TLS-terminating proxy via --web-cookie-secure.
  4. Token gate. When a token is configured (--web-token, or the environment variable ID_WEB_TOKEN), it is accepted in three forms: the cookie id_token, an Authorization: Bearer header, or a ?token= query parameter. The query form sets the cookie and then redirects to the clean path with the parameter removed. When no token is configured, this gate is open; id serve prints a warning at startup when a web listener is bound without --web-token.

Older documentation presents the web UI as an unauthenticated local tool and never mentions this layer. That is disagreement WEB-15: the Host allow-list, the Origin check and the token gate apply to every route in the code, and this chapter documents the code.

Body limits: a router-wide default body limit applies, and /api/upload overrides it with a larger route-scoped limit sized so that a file of exactly the maximum image size plus its multipart envelope fits.

Pages

Full HTML pages in the main router:

MethodPathPurpose
GET/Index / home: world list, globally-tagged documents, and a global-chat iframe.
GET/.well-known/id-transport-advertisementThe transport advertisement document.
GET/filesFile browser page.
GET/worldWorld page: the adapter surface for the hosted world. The path is the default; AppState.web_route parameterises it per app.
GET/settingsSettings page.
GET/peersDiscovered peers page.
GET/blocksOperator block-list page.
GET/groupsGroups page.
GET/edit/{*name}Editor/viewer for a file by name (wildcard).
GET/hash/{hash}Redirect from a content hash to its named file.
GET/view/{*name}Read-only view of a file by name.
GET/blob/{hash}Raw blob bytes with a Content-Type.

Correct route spellings (WEB-1)

The editor and view routes take a name, not a hash, and the name is a wildcard segment:

  • Edit: /edit/{*name}
  • View: /view/{*name}
  • Hash entry point: /hash/{hash}

WEB.md documents GET /edit/{hash} and GET /file/{name}. Neither route exists in the code. That is disagreement WEB-1; the spellings above are the routes routes.rs registers.

HTTP API and partials

MethodPathPurpose
GET/api/filesFile list, as an HTML partial for SPA navigation.
GET/api/home/feedHome feed partial.
GET/api/peersPeers partial.
GET, POST/api/blocksList blocks / create a block.
POST/api/blocks/removeRemove a block.
POST/api/saveSave editor content to the blob store.
POST/api/newCreate a new named file.
POST/api/renameRename, with optional archive of the original or replaced file.
POST/api/copyCopy a name to a new name.
POST/api/files/sendServer-side send of file references to another server.
POST/api/downloadDownload file content.
POST/api/deleteSoft-delete a file.
POST/api/restoreRestore a soft-deleted file. Returns 404 when the file is missing and 409 when it is not deleted.
POST/api/hard-deletePermanently delete a file.
POST/api/uploadImage upload, multipart, with the route-scoped body limit.
GET/api/imagesImage listing, paged, with a cursor clamped to the result set.
GET, POST, DELETE/api/tagsGet, set or delete tags. DELETE modes: exact match, all: true, and all_values: true. Binary values travel as value_b64. The tag wire protocol is in WebSocket protocols.
GET/api/tags/searchStructured tag search: q and ns parameters; key:, :value, key:value, quoted and bare terms, ANDed.
POST/api/identity/registerRegister a web client identity. Bounded by ID_WEB_MAX_IDENTITIES; see Configuration and environment.
GET/api/identity/meThe current identity.
POST/api/identity/nameUpdate the identity display name.
POST/api/seitan/inviteSeitan admission: create an invite.
POST/api/seitan/admitSeitan admission: admit with an invite.
GET/assets/{*path}Embedded static assets; see “Assets” below.

The delete pair is a web-layer construction: /api/delete and /api/restore implement soft delete on top of the FileOps hard delete described in Data stores and schemas.

World bridge HTTP routes

These 9 paths are merged into the main router always. The WebSocket socket path comes from [interfaces.web] in the app’s app.toml and defaults to /ws/world; see Configuration and environment.

MethodPathPurpose
POST/api/world/inviteMint a world guest invite. Fields: display_name, optional world, expires_in_secs, uses.
GET/api/world/host-viewHost view: snapshot, surface, and paged records. Paging uses an after cursor; the records revision is an FNV-1a 53-bit value.
GET/api/world/metricsWorld host metrics.
GET, POST/api/world/directoryDirectory read / signed directory write action.
GET/exploreScript-free HTML directory explorer: forms only, strict CSP default-src 'none'.
POST/explore/loginExplorer login: an admin token is exchanged for the id_explore session cookie, scoped to path /explore.
POST/explore/actExplorer directory action.
GET/inviteInvite landing page.
WS/ws/world (default socket)World session bridge; the frame protocol is in WebSocket protocols.

These 7 paths are merged into the main router always. Every one of them answers 404 unless a gallery was wired in with --gallery-dir or ID_GALLERY_DIR. The operator commands behind them are in Gallery, match-audit and walk.

MethodPathPurpose
GET/api/gallery/recordsSigned bundle records list. Filters: ?author= and ?name=.
GET/api/gallery/bundles/{content_hash}Bundle bytes, immutable cache. Answers 410 Gone, with a transparency entry, when the bundle is unlisted here.
GET/api/gallery/searchSearch with ?q=, ?category=, ?limit=. Result order: exact-name, then category, then most-recent-version.
GET/api/gallery/authors/{author}Author page by key.
GET/api/gallery/collectionsOperator-signed featured collections.
GET/api/gallery/collections/{operator}/{name}One collection.
GET/api/gallery/transparencyRemovals, refusals and reinstatements, plus the admission posture. Paging: ?after= and ?limit=.

WebSocket routes

PathProtocol
/ws/collab/{doc_id}Collaborative editing, binary MessagePack.
/ws/tagsTag-change broadcast, JSON text, server to client only.

Both protocols are specified in full in WebSocket protocols.

The program-only router

create_program_router serves one listener pinned to one world. It has 10 paths:

  • GET / — the program page.
  • GET /assets/{*path} — embedded static assets.
  • The full world bridge surface above (8 HTTP paths plus the world socket), bound at that world’s socket.

A publication mount serves exactly this router under a mounted prefix.

Content modes and themes

A file’s content mode is decided from its extension, and for text modes from its content:

ModeSelected forWire name
Media(Image|Video|Audio|Pdf)Media and PDF extensionsmedia
Rich.pm.json ProseMirror JSONrich
Markdown.md, .markdownmarkdown
Plain.txtplain
RawA long list of code and config extensions; also the default for unknown or missing extensionsraw
BinaryOnly when a text-mode file is not valid UTF-8binary

Editable modes: Rich, Markdown, Plain, Raw. Toolbar modes: Rich, Markdown, Plain. get_content_type maps extensions to MIME types and defaults to application/octet-stream.

The frontend ships exactly three DaisyUI themes, all on a #000000 background: sneak (default, blue #00aaff), arch (green #00ff00) and mech (orange #ff6600). The choice is stored in the localStorage key id-theme, applied as the data-theme attribute, cycled with Alt+T, and announced with a theme:change CustomEvent.

Assets: how they are built and served

Build, from web/package.json:

bun build src/main.ts --outdir=dist --minify --sourcemap=external --entry-naming=[name].[hash].js

CSS is built with the Tailwind v4 CLI from src/input.css to dist/styles.css. A manifest script then renames the stylesheet to its hashed name and writes the manifest the templates consume (AssetUrls).

Serving: web/dist is embedded into the binary at compile time with rust-embed (#[folder = "../../web/dist"], struct Assets) and served at /assets/{*path}. The checkout’s web/dist contains only a tracked .gitkeep; the assets are a build product, not source.

Asset naming and cache contract (WEB-4)

The cache contract is derived from the emitted file name:

FileCache header
main.<8 base36>.js and its .js.mappublic, max-age=31536000, immutable
styles.<8 lower-hex>.csspublic, max-age=31536000, immutable
Everything elseno-cache

WEB.md names the assets main.css and main.js. The build never emits either name. That is disagreement WEB-4; the hashed names above are what assets.rs recognises.

Worked example

Toy data: a node serving on the default port, with a web token set, and a file named shopping-list.txt.

Start the server (flags are specified in serve and publications):

$ id serve --web --port 3000 --web-token TOKEN

First visit with the token in the query string; the server sets the id_token cookie and redirects to the clean path:

GET /?token=TOKEN        → 302 → GET /
GET /                    → 200  (index page, cookie now set)

Read and edit the file by name:

GET  /view/shopping-list.txt   → 200  (read-only view)
GET  /edit/shopping-list.txt   → 200  (editor)
POST /api/save                 → 200  (editor content written to the blob store)
GET  /hash/0123abcd…           → 302  (redirect to the named file for that hash)
GET  /blob/0123abcd…           → 200  (raw bytes, Content-Type set)

A request from a disallowed host, or a cross-origin POST, is refused by the security layer before any handler runs — that refusal is the Host allow-list and Origin check above, not a per-route check.