serverApiHost

tcmts.cli.web.serverApiHost · #ud2f3rss · term · runs on the server

uses node:url

The #tcm/host instance the codebase's generated modules import (the server library calls it), so server functions see their call.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import type { ServerApiHost } from "#codebase/tcmts/cli/web";
import path from "node:path";
import { pathToFileURL } from "node:url";

export function serverApiHost(cb: Codebase): () => Promise<ServerApiHost> {
  let api: Promise<ServerApiHost> | undefined;
  return () =>
    (api ??= import(
      pathToFileURL(path.join(cb.lay.cacheDir, "tcm-host.js")).href
    ) as Promise<ServerApiHost>);
}

uses

used by