flotilla/e2e/harness/zooid/config.ts

28 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-08-06 15:43:57 +00:00
/**
* The virtual relays the container serves, and the only place their names are written down.
*
* zooid is multi-tenant: it binds a config to a Host header and serves any number of them from one
* process, so a second space costs a toml in docker/config and nothing else. The names are a union
* rather than a string so that a scenario naming a relay that has no config fails to compile
* instead of hanging on a 404 from the dispatcher.
*
* Each host is a name that resolves nowhere. The container is reached on loopback and told what to
* call itself, so that what it calls itself is a url a relay selection will keep — see transport.ts
* for why that matters, and `.test` is reserved by rfc 2606, so a url that escapes this process
* fails to connect rather than reaching a host.
*/
export const tenants = {
space: "space.test",
other: "other.test",
} as const
export type TenantName = keyof typeof tenants
export const tenantUrl = (name: TenantName) => `wss://${tenants[name]}/`
export const tenantNames = Object.keys(tenants) as TenantName[]
// Which tenant a url belongs to, for the transport's Host header. A url the app opens that is not
// one of these is a leak, and is reported as one rather than dialled.
export const tenantByUrl = new Map(tenantNames.map(name => [tenantUrl(name), tenants[name]]))