Can NestJS HttpService be configured with a global custom DNS resolver?
0 reputation · 21 Feb 2022, 02:51 UTC
When building a NestJS application that relies on the injected HttpService for outbound HTTPS calls, I need to ensure that all requests use a specific DNS resolver (e.g., an internal DNS server) and optionally relax certificate validation for internal services with self‑signed certificates. The HttpService is a thin wrapper around Axios, which ultimately uses Node’s built‑in http/https modules; NestJS does not expose a global option to override the DNS lookup function or to toggle rejectUnauthorized centrally. Configuration must be supplied per‑instance via a custom https.Agent, either when registering HttpModule or by overriding the HttpService’s underlying axios instance.
Is there a supported way to register a custom DNS lookup function (or a custom https.Agent) that applies to every HttpService instance without manually providing it each time? Can Node.js environment variables such as NODE_OPTIONS=--dns-result-order be relied upon within a NestJS process to affect DNS resolution globally, and if so, how should they be integrated safely? What patterns or provider overrides are recommended to achieve a centralized DNS/TLS configuration while preserving type safety and testability?