← Catalog

@e9n/pi-webserver

Shared HTTP server for pi — authenticated web host with extension mount points

Package

Install

Install with PiG

pig install npm:@e9n/pi-webserver

Install with Pi

pi install npm:@e9n/pi-webserver
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.3.2 (README.md). PiG does not review it.

@e9n/pi-webserver

Shared HTTP server for pi — one port, shared auth, and an event-bus mount system that other extensions plug into.

Features

  • Single shared port — all extensions serve from one HTTP server (default 4100)
  • Basic auth — protects page routes with HTTP Basic authentication
  • API bearer token auth — separate full-access and read-only tokens for /api/* routes
  • Cookie session auth — browser-friendly login page for API-token-only setups
  • Prefix routing — longest-prefix match; prefix is stripped before calling the handler
  • Event bus mounting — extensions mount via pi.events.emit("web:mount", ...) without importing
  • Built-in dashboard — / lists all registered mounts with links
  • Autostart — optionally start on session init via settings

Setup / Settings

Add to ~/.pi/agent/settings.json (project overrides in <project>/.pi/settings.json):

{
  "pi-webserver": {
    "autostart": true,
    "port": 4100,
    "auth": "mypassword",
    "apiToken": "my-secret-token",
    "apiReadToken": "my-read-token"
  }
}
KeyTypeDefaultDescription
autostartbooleanfalseStart the server automatically on session start
portnumber4100HTTP port
authstring | nullnullBasic auth — "password" or "user:password"
apiTokenstring | nullnullBearer token for full API access (all methods)
apiReadTokenstring | nullnullBearer token for read-only API access (GET/HEAD)

Commands

CommandDescription
/webStart on port 4100, or stop if already running
/web <port>Start on a specific port
/web stopStop the server
/web statusShow URL, auth status, and all mounts
/web port [number]Show or change the current port
/web auth <password>Enable Basic auth (username: pi)
/web auth <user:pass>Enable Basic auth with custom username
/web auth offDisable Basic auth
/web api <token>Set bearer token for full API access
/web api read <token>Set read-only bearer token (GET/HEAD only)
/web api offDisable API token auth
/web apiShow API token status and mounted API routes

Web UI

RouteDescription
/Dashboard listing all registered mounts
/_api/mountsJSON: all mounts (Basic auth)
/_api/mounts/dashboardJSON: non-API mounts (for nav shells)
/_auth/loginBrowser login page (when only API tokens are set)
/_auth/logoutClear session cookie
/api/*API routes — Bearer token auth (or open if no token set)

For extension authors

Mount a page route via the event bus (no import needed):

export default function (pi: ExtensionAPI) {
  pi.events.on("web:ready", () => {
    pi.events.emit("web:mount", {
      name: "my-ext",
      label: "My Extension",
      description: "Does cool things",
      prefix: "/my-ext",
      handler: (req, res, subPath) => {
        res.writeHead(200, { "Content-Type": "text/html" });
        res.end("<h1>Hello</h1>");
      },
    });
  });
}

Mount an API route under /api/*:

pi.events.emit("web:mount-api", {
  name: "my-ext-api",
  label: "My Extension API",
  prefix: "/my-ext",           // mounts at /api/my-ext
  handler: (req, res, subPath) => { ... },
});

Events

EventDirectionPayload
web:ready← emitted by webserver on session start{}
web:info→ webserver replies synchronously when listening{ reply: ({ port, url }) => void }
web:mount→ webserver listensMountConfig
web:unmount→ webserver listens{ name: string }
web:mount-api→ webserver listensMountConfig
web:unmount-api→ webserver listens{ name: string }

Install

pi install npm:@e9n/pi-webserver

License

MIT