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:
- What the object form does (options forwarded to
buildConnector()) - What the function form does (custom connector)
- What arguments the function receives (
hostname,host,protocol,port,servername,localAddress,httpSocket) - That undici wraps custom functions to inject
socketPathandallowH2 - How to use common patterns like TLS customization or Unix socket connections
Changes
- Added description for
connectparameter (lines 30-32):- Explains both the object form (
ConnectOptions→ forwarded tobuildConnector()) and function form (custom connector) - Documents the function signature:
(options, callback)whereoptionscontains{ hostname, host, protocol, port, servername, localAddress, httpSocket }andcallbackfollows(error, socket) - Documents the wrapping behavior: undici injects
socketPathandallowH2into options when a function is provided - Cross-references
buildConnector()andConnectOptions
- Explains both the object form (
- Added example: Connect with TLS options (object form) — shows passing
rejectUnauthorizedandcaas aConnectOptionsobject - Added example: Connect via Unix domain socket — shows using
socketPathfor IPC connections (e.g., Docker socket) - 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
docs/docs/api/Client.md
Partially addresses #886