@volter/world-runtime 3.0.13 → 3.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/world-view.ts CHANGED
@@ -8,7 +8,7 @@ import { join, resolve } from 'node:path';
8
8
  import { serveHttp, stateDirName } from '@volter/world-core/runtime';
9
9
  import { followParentPins, LocalBranches } from './local-branches.ts';
10
10
  import { mountWorld, type MountedWorld } from './served-world.ts';
11
- import { localWorldOrigin, pathOfWorld, siteOfHost, worldDoorUnderConsole, worldOfHost } from './world-origins.ts';
11
+ import { localWorldOrigin, pagesOfHost, pagesOriginOf, pathOfWorld, siteOfHost, worldDoorUnderConsole, worldOfHost } from './world-origins.ts';
12
12
 
13
13
  /** A console as a host mounts it (`@volter/world-console`): answer a request under `base`, or null. */
14
14
  export type ViewConsole = { handle: (request: Request, base: string, opts?: { worldOrigin?: boolean }) => Promise<Response | null> };
@@ -51,7 +51,9 @@ export async function serveWorldView(name: string, opts: { /** the person signed
51
51
  const browserOrigin = origins ? (served: string) => (proxied && (base === null || served === base) ? proxied.origin : port ? localWorldOrigin(served, port) : null) : undefined;
52
52
  // sites are routed at each World's own *.localhost origin, never behind the proxy
53
53
  const sitesOrigin = origins && !proxied ? (served: string) => (port ? localWorldOrigin(served, port) : null) : undefined;
54
- const mountAt = (at: string): Promise<MountedWorld> => mountWorld(loadWorldConfig(join(at, stateDirName(), 'world.json'), at).config.id, { root: at, branches: (served) => branches.doorsFor(served), ...(browserOrigin ? { browserOrigin } : {}), ...(sitesOrigin ? { sitesOrigin } : {}), ...(local ? { localTrust: true, ...(opts.localPerson ? { localPerson: opts.localPerson } : {}) } : {}) });
54
+ // the content plane beside each World's origin (`<world>--<org>--pages.localhost`): its twins' pages, apart from its doors
55
+ const pagesOrigin = origins && !proxied ? (served: string) => (port ? pagesOriginOf(served, 'http:', 'localhost', port) : null) : undefined;
56
+ const mountAt = (at: string): Promise<MountedWorld> => mountWorld(loadWorldConfig(join(at, stateDirName(), 'world.json'), at).config.id, { root: at, branches: (served) => branches.doorsFor(served), ...(browserOrigin ? { browserOrigin } : {}), ...(sitesOrigin ? { sitesOrigin } : {}), ...(pagesOrigin ? { pagesOrigin } : {}), ...(local ? { localTrust: true, ...(opts.localPerson ? { localPerson: opts.localPerson } : {}) } : {}) });
55
57
  const branches: LocalBranches = new LocalBranches({ dir: join(root, stateDirName(), 'branches'), origin: () => loopback, worlds, mount: mountAt, ...(opts.announce ? { announce: opts.announce } : {}) });
56
58
  // THE WORLD'S OWN BRANCHES, one served at a time: serving another stops this one's twins and starts that one's under the
57
59
  // same served name (its tokens and sessions are the World's, so the page stays open); `.volter/current` follows, as
@@ -82,7 +84,7 @@ export async function serveWorldView(name: string, opts: { /** the person signed
82
84
  if (branch === loadWorldConfig(join(root, stateDirName(), 'world.json'), root).config.id) rmSync(current, { force: true }); else writeFileSync(current, `${branch}\n`);
83
85
  } finally { switching = false; }
84
86
  };
85
- const mountOpts = { root, branches: (served: string) => branches.doorsFor(served), ...(browserOrigin ? { browserOrigin } : {}), ...(sitesOrigin ? { sitesOrigin } : {}), ...(local ? { localTrust: true, ...(opts.localPerson ? { localPerson: opts.localPerson } : {}) } : {}), serveBranch };
87
+ const mountOpts = { root, branches: (served: string) => branches.doorsFor(served), ...(browserOrigin ? { browserOrigin } : {}), ...(sitesOrigin ? { sitesOrigin } : {}), ...(pagesOrigin ? { pagesOrigin } : {}), ...(local ? { localTrust: true, ...(opts.localPerson ? { localPerson: opts.localPerson } : {}) } : {}), serveBranch };
86
88
  let world = await mountWorld(name, mountOpts);
87
89
  base = world.served;
88
90
  worlds.set(world.served, world);
@@ -104,6 +106,9 @@ export async function serveWorldView(name: string, opts: { /** the person signed
104
106
  // a site the World's twins answer, under the World's local origin (`<hostname>.<world>--<org>.localhost`)
105
107
  const site = origins && !proxied ? siteOfHost(at.hostname, worlds.keys()) : undefined;
106
108
  if (site) return worlds.get(site.world)!.site(request, site.site);
109
+ // a World's content plane serves that World's twins' pages and nothing else of this view's (no console)
110
+ const pagesFor = origins && !proxied ? pagesOfHost(at.hostname, worlds.keys()) : undefined;
111
+ if (pagesFor) return path === '/-/ping' ? Response.json({ ok: true, worlds: [pagesFor] }) : worlds.get(pagesFor)!.handle(request);
107
112
  const own = origins ? (proxied && at.host === proxied.host ? base! : worldOfHost(at.hostname, worlds.keys())) : undefined;
108
113
  if (own === null) return Response.json({ error: `no world at ${at.host}` }, { status: 404 });
109
114
  // the bare address, typed into a browser, is the World's page: at its own origin when it has one