docs: improve connect option documentation in Client.md by AliMahmoudDev · Pull Request #5344 · nodejs/undici (original) (raw)

Summary

Improves the connect option documentation in Client.md to address the lack of description for one of the most important configuration options.

Problem

The connect option in ClientOptions was documented as:

* **connect** `ConnectOptions | Function | null` (optional) - Default: `null`.

This had no description at all — just a type signature and default value. Users had no guidance on:

Changes

  1. Added description for connect parameter (lines 30-32):
    • Explains both the object form (ConnectOptions → forwarded to buildConnector()) and function form (custom connector)
    • Documents the function signature: (options, callback) where options contains { hostname, host, protocol, port, servername, localAddress, httpSocket } and callback follows (error, socket)
    • Documents the wrapping behavior: undici injects socketPath and allowH2 into options when a function is provided
    • Cross-references buildConnector() and ConnectOptions
  2. Added example: Connect with TLS options (object form) — shows passing rejectUnauthorized and ca as a ConnectOptions object
  3. Added example: Connect via Unix domain socket — shows using socketPath for IPC connections (e.g., Docker socket)
  4. Improved custom connector example — renamed from "Custom connector" to "Custom connector (function form)", added a note callout explaining the wrapping behavior, and added a cross-reference to Connector.md

Files changed

Partially addresses #886