Skip to content

Documentation / @super-line/server / ServerOptions

Interface: ServerOptions<C, A>

Defined in: index.ts:198

Options for createSocketServer.

Type Parameters

C

C extends Contract

A

A extends AuthResult<C>

Properties

adapter?

optional adapter?: Adapter

Defined in: index.ts:204

Cross-node fan-out adapter. Defaults to a per-server in-memory adapter.


authenticate

authenticate: (req) => Awaitable<A>

Defined in: index.ts:208

Runs at the HTTP upgrade. Return { role, ctx }, or throw to reject with 401.

Parameters

req

IncomingMessage

Returns

Awaitable<A>


authorizeSubscribe?

optional authorizeSubscribe?: (topic, ctx, conn) => Awaitable<boolean | void>

Defined in: index.ts:214

Runs on each client subscribe. Return false or throw to deny.

Parameters

topic

string

ctx

CtxUnion<A>

conn

Conn

Returns

Awaitable<boolean | void>


backpressure?

optional backpressure?: Backpressure

Defined in: index.ts:225

Guard against slow consumers: when a connection's send buffer exceeds the limit, close or drop.


describeConn?

optional describeConn?: (conn) => Record<string, unknown>

Defined in: index.ts:212

Extra fields merged into the connection's cluster descriptor (e.g. { plan }). ctx is never auto-serialized.

Parameters

conn

Conn

Returns

Record<string, unknown>


heartbeat?

optional heartbeat?: false | { interval?: number; maxMissed?: number; }

Defined in: index.ts:223

Heartbeat: one timer pings every connection each interval ms (updating conn.lastPingAt/lastPongAt). Set maxMissed to terminate a connection that misses that many consecutive pongs. false disables it. Defaults to { interval: 30_000 } (no reaping).


identify?

optional identify?: (conn) => string | undefined

Defined in: index.ts:210

Stable user key for a connection (powers cluster.byUser, isOnline, and toUser).

Parameters

conn

Conn

Returns

string | undefined


onConnection?

optional onConnection?: (conn, ctx) => void

Defined in: index.ts:227

Called once per accepted connection.

Parameters

conn

Conn

ctx

CtxUnion<A>

Returns

void


onDisconnect?

optional onDisconnect?: (conn, ctx, code) => void

Defined in: index.ts:229

Called when a connection closes, with the WebSocket close code.

Parameters

conn

Conn

ctx

CtxUnion<A>

code

number

Returns

void


onError?

optional onError?: (error, info) => void

Defined in: index.ts:231

Called for any error thrown in middleware/handlers (after the client is replied to).

Parameters

error

unknown

info

MiddlewareInfo

Returns

void


path?

optional path?: string

Defined in: index.ts:206

Only handle upgrades for this pathname; others are left untouched.


serializer?

optional serializer?: Serializer

Defined in: index.ts:202

Wire serializer; MUST match the client. Defaults to jsonSerializer.


server?

optional server?: Server<typeof IncomingMessage, typeof ServerResponse>

Defined in: index.ts:200

The http.Server to attach to (compose with Express/Fastify/Hono).


use?

optional use?: Middleware<A>[]

Defined in: index.ts:216

Middleware chain run before req/subscribe handlers (rate-limit, authz, logging, metrics).

Released under the MIT License.