TLS: self-signed certificates
Use case
Connect to a server with a self-signed TLS certificate in development or testing environments (Node.js only).
Smallest working example
import { createClient } from '@parcely/core'
const http = createClient({
baseURL: 'https://localhost:3443',
tls: {
rejectUnauthorized: false,
},
})
const { data } = await http.get('/health')
How it works
When tls is set, parcely lazy-imports undici (installed via optionalDependencies) and creates a custom Agent with the specified TLS options. This is passed to fetch as a dispatcher.
Axios equivalent
// axios (Node):
import https from 'https'
const http = axios.create({
baseURL: 'https://localhost:3443',
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
})
// parcely:
const http2 = createClient({
baseURL: 'https://localhost:3443',
tls: { rejectUnauthorized: false },
})
Notes and gotchas
- Node-only. In browsers, Bun, and Deno, the
tlsoption is ignored and a one-shotconsole.warnis emitted. rejectUnauthorized: falseemits a one-shotconsole.warnto remind you not to use it in production.- For production with internal CAs, use the
caoption instead. See TLS: custom CA. - The
TlsConfigtype is{ rejectUnauthorized?: boolean; ca?: string | string[] }.