iterate.com / dash

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

dash / app.tsmain at da05cae

// app.ts — THE DASH, as config/worker.ts mounts it on dash.<domain>: the host of one page. It
// answers the member's `itx` socket, what the UI kit's shell asks of its host, and the app's
// files. What the page shows is said in public/app.js.
//
// A MIND BORN FROM ANOTHER MIND'S REPOS has its own copy of the Dash and may change it. Once it
// has, a pull of /repos/dash is refused until upstream's commits and its own are brought together.
import { type AppDescription, serveFiles, type IterateConfigEntrypoint } from "iterate/sdk";
import { openFile } from "@repos/stdlib/open-files.ts";
import theme from "@repos/stdlib/theme.css";
import index from "./index.html";
import files from "./public/";

/** WHAT THE DASH SAYS OF ITSELF: the mind's sign-in pages show its name and its icon, and
 *  open on the passkey, since it is for members. */
const DASH: AppDescription = { name: "Dash", icon: "/icon.svg", for: "members" };

/** `icon`: the answer for the mind's icon, which every app serves as its own
 *  (open-files.ts of /repos/stdlib). */
export function dashApp({ icon }: { icon: () => Response }) {
  return {
    /** The app's description and icon, for anyone: worker.ts asks this before its guard. */
    open: (request: Request) => openFile(request, DASH, icon),
    /** Every request on the app's host. worker.ts guards it, so a member alone gets here. */
    fetch(request: Request, host: Pick<IterateConfigEntrypoint, "auth">) {
      // The page's own socket (public/app.js opens it), and what @iterate-com/ui's shell asks of
      // its host: which platform this page talks to, the one mind this app serves, its "Sign out".
      const page = host.auth.memberPage(request);
      if (page) return page;
      // the app's own files, and the theme that every app of this mind shares
      return serveFiles(request, { index, files: { ...files, "theme.css": theme } });
    },
  };
}