UNPKG

get-it

Version:

Generic HTTP request library for node, browsers and workers

32 lines (27 loc) 724 B
import type {Middleware} from 'get-it' import {isBrowserOptions} from '../util/isBrowserOptions' /** @public */ export function mtls(config: any = {}) { if (!config.ca) { throw new Error('Required mtls option "ca" is missing') } if (!config.cert) { throw new Error('Required mtls option "cert" is missing') } if (!config.key) { throw new Error('Required mtls option "key" is missing') } return { finalizeOptions: (options) => { if (isBrowserOptions(options)) { return options } const mtlsOpts = { cert: config.cert, key: config.key, ca: config.ca, } return Object.assign({}, options, mtlsOpts) }, } satisfies Middleware }