Skip to content

@gluonjs/core / packages/ssr/src/tenant / serializeTenantContext

Function: serializeTenantContext() ​

serializeTenantContext<Tenant>(context): string

Serializes only JSON-compatible tenant data for an explicit client handoff.

Type Parameters ​

Tenant ​

Tenant extends TenantJsonValue

Parameters ​

context ​

TenantContext<Tenant>

Returns ​

string

Example ​

Serialize only JSON-compatible tenant data for hydration:

ts
import { createTenantContext, deserializeTenantContext, installTenant, resolveTenant, serializeTenantContext, tenantInjectionKey, type TenantContext, type TenantJsonValue, type TenantResolutionRequest, type TenantResolver } from '@gluonjs/ssr/tenant';
const request: TenantResolutionRequest = { url: 'https://acme.example/', hostname: 'acme.example', headers: {} };
const resolver: TenantResolver = (input) => ({ id: input.hostname, locale: 'en-GB' });
const context: TenantContext = await resolveTenant(request, resolver);
const explicit = createTenantContext({ id: 'acme' } satisfies TenantJsonValue, { hostname: request.hostname });
const serialized = serializeTenantContext(context);
const restored = deserializeTenantContext(serialized);
console.log(installTenant, tenantInjectionKey, explicit, restored);

Version-matched documentation. Examples are checked against the public package contracts.