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
| Property | Type | Description |
|---|---|---|
address | string | The client’s IP address. |
port | number (optional) | The client’s port number, if available. |
transport | "tcp" | "udp" | string | The 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();
};Cookie Utilities
A lightweight utility module for managing HTTP cookies in TezX applications. Includes functions for reading, parsing, setting, and deleting cookies in a consistent and type-safe way.
JWT Utility
Provides JWT signing and verification using HMAC (HS256 or HS512) for secure token-based authentication Bun environments (with Web Crypto API).