IF Commons GitHub

physical/serve

Written to: 3 requirements: 3 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-anyfs-serve-physical FR-001, 0004-anyfs-serve-physical FR-002, 0004-anyfs-serve-physical FR-003

The server: serveStore hosts the handler of a store on node:http through the server of commons, so that it runs on Bun and on Node. It listens on the loopback unless the program names an address with an exposure that names the hosts it may be asked for, and it starts with a random token that the program shows to the person who started it, unless the program gives its own way to know who asks.

import { memoryStore } from "@intellectual-frontiers/anyfs/memory";
import { serveStore } from "./serve.ts";
const running = await serveStore(memoryStore(), {});
running.url; // "http://127.0.0.1:49152/"
await running.close();

Source: commons/anyfs-serve/src/physical/serve.ts

1 of 3 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

ServeStoreOptionstypeno test imports it
type ServeStoreOptions = Omit<HandlerOptions, "authenticator" | "hosts"> & { /** The port; 0 asks for a free one. */ … (648 characters)
type ServeStoreOptions = Omit<HandlerOptions, "authenticator" | "hosts"> & {
  /** The port; 0 asks for a free one. */
  readonly port?: number;
  /** Where it may listen: the loopback by default. */
  readonly exposure?: Exposure;
  /** Who may ask; the token the server makes by default. */
  readonly authenticator?: Authenticator;
  /** The token to use where none of the above is given; made at random where not given. */
  readonly token?: string;
  /** Told the token the server made, so that the program can show it to the person who started the server (it is never logged by the server). */
  readonly onToken?: (token: string) => void;
};

What the server is told besides what the handler is.

Servingtypeno test imports it
type Serving = {
  /** The address, with the port. */
  readonly url: string;
  readonly port: number;
  /** The token that is accepted where the server made it, else undefined. */
  readonly token: string | undefined;
  close(): Promise<void>;
};

A running server.

serveStorefunction
function serveStore(store: Store<Viewable>, options?: ServeStoreOptions): Promise<Result<Serving, string>>

Hosts a store as WebDAV, or says why it cannot: an address that is not the loopback needs an exposure that names its hosts.

Imported by 9 tests of the run (9 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.