|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { rootCertificates } from 'node:tls'; |
| 9 | +import { readFile } from 'node:fs/promises'; |
| 10 | +import { getCACertificates, rootCertificates, setDefaultCACertificates } from 'node:tls'; |
10 | 11 | import type { Plugin } from 'vite'; |
11 | 12 |
|
12 | 13 | export function createAngularServerSideSSLPlugin(): Plugin { |
@@ -35,17 +36,30 @@ export function createAngularServerSideSSLPlugin(): Plugin { |
35 | 36 | httpServer.ALPNProtocols = ['http/1.1']; |
36 | 37 | } |
37 | 38 |
|
38 | | - // TODO(alanagius): Replace `undici` with `tls.setDefaultCACertificates` once we only support Node.js 22.18.0+ and 24.5.0+. |
39 | | - // See: https://nodejs.org/api/tls.html#tlssetdefaultcacertificatescerts |
| 39 | + const { cert } = https; |
| 40 | + const additionalCerts = Array.isArray(cert) ? cert : [cert]; |
| 41 | + |
| 42 | + // TODO(alanagius): Remove the `if` check once we only support Node.js 22.18.0+ and 24.5.0+. |
| 43 | + if (getCACertificates && setDefaultCACertificates) { |
| 44 | + const currentCerts = getCACertificates('default'); |
| 45 | + setDefaultCACertificates([...currentCerts, ...additionalCerts]); |
| 46 | + |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + // TODO(alanagius): Remove the below and `undici` dependency once we only support Node.js 22.18.0+ and 24.5.0+. |
40 | 51 | const { getGlobalDispatcher, setGlobalDispatcher, Agent } = await import('undici'); |
41 | 52 | const originalDispatcher = getGlobalDispatcher(); |
42 | | - const { cert } = https; |
43 | | - const certificates = Array.isArray(cert) ? cert : [cert]; |
| 53 | + const ca = [...rootCertificates, ...additionalCerts]; |
| 54 | + const extraNodeCerts = process.env['NODE_EXTRA_CA_CERTS']; |
| 55 | + if (extraNodeCerts) { |
| 56 | + ca.push(await readFile(extraNodeCerts)); |
| 57 | + } |
44 | 58 |
|
45 | 59 | setGlobalDispatcher( |
46 | 60 | new Agent({ |
47 | 61 | connect: { |
48 | | - ca: [...rootCertificates, ...certificates], |
| 62 | + ca, |
49 | 63 | }, |
50 | 64 | }), |
51 | 65 | ); |
|
0 commit comments