Skip to content

Commit aa8afec

Browse files
committed
fixup! fix(@angular/build): simplify SSL handling for with SSR
1 parent 33da0a0 commit aa8afec

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

packages/angular/build/src/tools/vite/plugins/ssr-ssl-plugin.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import { rootCertificates } from 'node:tls';
910
import type { Plugin } from 'vite';
1011

1112
export function createAngularServerSideSSLPlugin(): Plugin {
@@ -15,20 +16,23 @@ export function createAngularServerSideSSLPlugin(): Plugin {
1516
async configureServer({ config, httpServer }) {
1617
const {
1718
ssr,
18-
server: { https },
19+
server: { https: cert },
1920
} = config;
2021

21-
if (!ssr || !https) {
22+
if (!ssr || !cert) {
2223
return;
2324
}
2425

26+
// TODO(alanagius): Replace `undici` with `tls.setDefaultCACertificates` once we only support Node.js 22.18.0+ and 24.5.0+.
27+
// See: https://nodejs.org/api/tls.html#tlssetdefaultcacertificatescerts
2528
const { getGlobalDispatcher, setGlobalDispatcher, Agent } = await import('undici');
2629
const originalDispatcher = getGlobalDispatcher();
30+
const certificates = Array.isArray(cert) ? cert : [cert];
2731

2832
setGlobalDispatcher(
2933
new Agent({
3034
connect: {
31-
ca: [...getCerts(https.key), ...getCerts(https.cert)].join('\n'),
35+
ca: [...rootCertificates, ...certificates],
3236
},
3337
}),
3438
);
@@ -39,24 +43,3 @@ export function createAngularServerSideSSLPlugin(): Plugin {
3943
},
4044
};
4145
}
42-
43-
function getCerts(
44-
items: string | Buffer | (string | Buffer | { pem: string | Buffer })[] | undefined,
45-
): string[] {
46-
if (!items) {
47-
return [];
48-
}
49-
50-
const certs: string[] = [];
51-
if (Array.isArray(items)) {
52-
for (const item of items) {
53-
const value = typeof item === 'string' ? item : item.toString('utf-8');
54-
certs.push(value.trim());
55-
}
56-
} else {
57-
const value = typeof items === 'string' ? items : items.toString('utf-8');
58-
certs.push(value.trim());
59-
}
60-
61-
return certs;
62-
}

0 commit comments

Comments
 (0)