Skip to content

GatewayMetadata

reference
1 min readUpdated

Kind: Interface

Source: packages/websockets/interfaces/gateway-metadata.interface.ts

Part of: Websockets

External interface

GatewayMetadata defines the configuration used to initialize and operate a WebSocket gateway. It captures the gateway namespace, HTTP path, client-serving behavior, transport adapters/parsers, and connection or heartbeat timeout settings.

Properties

PropertyType
namespace`string
pathstring
serveClientboolean
adapterany
parserany
connectTimeoutnumber
pingTimeoutnumber
pingIntervalnumber
upgradeTimeoutnumber
maxHttpBufferSizenumber
allowRequest`( req: any, fn: (err: string
transports`Array<'polling'
allowUpgradesboolean
perMessageDeflate`boolean
httpCompression`boolean
wsEnginestring
initialPacketany
cookieany
corsCorsOptions
allowEIO3boolean
destroyUpgradeboolean
destroyUpgradeTimeoutnumber

Diagram

mermaid
graph LR
  GatewayMetadata --> Namespace["namespace: string | RegExp"]
  GatewayMetadata --> Path["path: string"]
  GatewayMetadata --> Client["serveClient: boolean"]
  GatewayMetadata --> Transport["adapter / parser"]
  GatewayMetadata --> Timeouts["Connection and upgrade timeouts"]
  GatewayMetadata --> Heartbeat["Ping interval and timeout"]
  GatewayMetadata --> Buffer["maxHttpBufferSize"]

  Timeouts --> Connect["connectTimeout"]
  Timeouts --> Upgrade["upgradeTimeout"]
  Heartbeat --> PingInterval["pingInterval"]
  Heartbeat --> PingTimeout["pingTimeout"]

Usage

ts
import type { GatewayMetadata } from './interfaces/gateway-metadata.interface';

const chatGatewayMetadata: GatewayMetadata = {
  namespace: '/chat',
  path: '/socket.io',
  serveClient: true,
  adapter: undefined,
  parser: undefined,
  connectTimeout: 10_000,
  pingTimeout: 20_000,
  pingInterval: 25_000,
  upgradeTimeout: 10_000,
  maxHttpBufferSize: 1e6,
};

// Pass this metadata to the gateway/WebSocket server initialization layer.
initializeGateway(chatGatewayMetadata);

AI Coding Instructions

  • Use namespace to isolate gateway endpoints; provide a RegExp only when dynamic namespace matching is required.
  • Keep path aligned with the client connection configuration, or clients will fail to establish a WebSocket connection.
  • Configure pingInterval and pingTimeout together; ensure the timeout allows for expected network latency.
  • Treat adapter and parser as integration points for the underlying WebSocket implementation and provide compatible instances.
  • Set maxHttpBufferSize conservatively to limit oversized payloads and reduce memory-pressure risks.

Relationships

  • IMPORTS → CorsOptions

Was this page helpful?

Download as PDF
GatewayMetadata — NestJS head-to-head