Skip to content

Adding to the app

A module can add to the app what a tool cannot: a page that shows something without HADAL, a button on the rail, or a row in the menu. This page tells about the parts that it can add. The members of web are in the web reference.

The second argument of the default export, web, registers these parts while the module loads:

  • Routes on the server, under /api/x/<module>/. The browser module calls them. Keys and other secrets stay on the server. See Routes.
  • A browser module: a .js file that the app loads in the tabs of the people that it is for. Through pocket, the app’s API for extensions, it adds rail buttons, pages, sheets, panels, status-line items, menu rows, and launcher actions, and says how its tools’ calls show. See Browser modules.
  • Commands for the message box (/name). They run on the server, and need no browser module. See Slash commands.
  • A presentation (since 0.28.0, experimental) for an input this module sends. The transcript shows one line, which opens to the message, or hides it until Find. The model still reads the message in full. See web.presentEntry. Each browser chooses open, folded, or hidden: a person in the row’s message sheet, and a browser module, for its own kinds, with pocket.entryPresentation, which also reads the choice. An input stored as the module’s own kind is not a person’s message: it cannot be sent again, and pocket.messages leaves it out.
  • Public pages (since 0.22.0, experimental) for anyone with one of the module’s links, with no sign-in. See Public pages.
import type { Host, Web } from "./_pocket.d.ts";
export default function createUsage(_host: Host, web: Web) {
web.route("GET", "usage", async ({ signal }) => fetchUsage(signal)); // GET /api/x/usage/usage
web.client("usage.js"); // the browser module beside this file
}

examples/server-status.ts and examples/server-status.js are a complete module with a route, a page, and events.

What a module adds to the app goes by the name of its file. For example, server-status.ts has the name server-status. Its routes are at /api/x/server-status/, and its browser module at /x/server-status/.

File names are different across the drop-in folder and the built-in modules, so these addresses never collide. A module that adds to the app must have a name of letters, digits, -, and _, that starts with a letter or a digit, up to a length.

The parts install and go with the module’s extensions:

  • An edit replaces them in one step.
  • When a new version does not load, the parts of the version before stay.
  • When the owner turns the module off, HADAL removes them, and closes a page of the module that is open.

These pages describe HADAL 0.29.0. Your copy has the pages of its own version in its docs/ folder.