TezXTezX
Helpers

getConnInfo

Import

import { getConnInfo } from "tezx/helper";

Usage

import { getConnInfo } from "tezx/helper";

const clientInfo = getConnInfo(ctx);
console.log(clientInfo);
// Output example:
// {
//   address: "192.168.1.101",
//   port: 54321,
//   transport: "tcp",
//   family: "IPv4"
// }

Parameters

  • ctx: Context – The current request context object.

Returns

NetAddr | undefined – An object containing the client’s connection details, or undefined if unavailable.

Properties

PropertyTypeDescription
addressstringThe client’s IP address.
portnumber (optional)The client’s port number, if available.
transport"tcp" | "udp" | stringThe transport protocol used (TCP, UDP, etc.).
family"IPv4" | "IPv6" | "Unix"The address family of the client connection.

Example: Using in Middleware

import { getConnInfo } from "tezx/helper";

export const logClientInfo = async (ctx, next) => {
  const client = getConnInfo(ctx);
  console.log(`Incoming request from ${client?.address}:${client?.port} (${client?.family})`);
  await next();
};