Skip to main content

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 tls option is ignored and a one-shot console.warn is emitted.
  • rejectUnauthorized: false emits a one-shot console.warn to remind you not to use it in production.
  • For production with internal CAs, use the ca option instead. See TLS: custom CA.
  • The TlsConfig type is { rejectUnauthorized?: boolean; ca?: string | string[] }.