iterate.com / stdlib

git clone https://git.iterate.com/repos/stdlib

stdlib / open-files.tsmain at 41005ca

// open-files.ts — WHAT AN APP SAYS OF ITSELF TO ANYONE: its description, which the app writes as
// a typed object in its app.ts (iterate/sdk `AppDescription`), and its icon. The mind's sign-in
// pages ask for both before a person has signed in, and show the app's name and icon to the
// person who signs in from it. So config/worker.ts answers these two before its guard:
//
//   return dash.open(request) || this.auth.require(request) || dash.fetch(request, this);
//
// Every other file of an app stays behind the guard.
//
// THE ICON IS THE MIND'S, one file for every app: config/worker.ts hands each app the answer for
// it (`icon`). An app keeps no icon of its own, so the mind's apps and its website show one logo.
// The icon is answered on the app's own host, at the path its description names: the sign-in
// pages take an icon from the app's own origin alone.
import { type AppDescription, serveAppDescription } from "iterate/sdk";

/** The answer for the app's description (at `/.well-known/iterate-app`) or for the icon that it
 *  names, and null for any other request. */
export function openFile(request: Request, app: AppDescription, icon: () => Response) {
  const described = serveAppDescription(request, app);
  if (described) return described;
  return new URL(request.url).pathname === app.icon ? icon() : null;
}