From 5889d643960d0bf2f573badfae85b125c85217be Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 13 Dec 2023 13:02:29 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): construct SSR request URL using server resolvedUrls With vite `header.host` is undefined when SSL is enabled. This resulted in an invalid URL to be constructed. Closes #26652 --- .../src/builders/dev-server/vite-server.ts | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts b/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts index efc409b76a04..c7048a8b99c6 100644 --- a/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts +++ b/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts @@ -33,7 +33,6 @@ import { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema'; import { loadProxyConfiguration } from './load-proxy-config'; import type { NormalizedDevServerOptions } from './options'; import type { DevServerBuilderOutput } from './webpack-server'; -import { ConnectionOptions } from 'node:tls'; interface OutputFileRecord { contents: Uint8Array; @@ -681,11 +680,9 @@ export async function setupServer( } transformIndexHtmlAndAddHeaders(url, rawHtml, res, next, async (html) => { - const url = new URL(req.originalUrl ?? '/', server.resolvedUrls?.local[0]); - const { content } = await renderPage({ document: html, - route: url.toString(), + route: new URL(req.originalUrl ?? '/', server.resolvedUrls?.local[0]).toString(), serverContext: 'ssr', loadBundle: (uri: string) => // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -800,25 +797,6 @@ export async function setupServer( configuration.plugins ??= []; configuration.plugins.push(basicSslPlugin()); } - - if (ssr) { - // Patch the TLS module to allow self signed certificate requests when running SSR. - // We cannot use `NODE_EXTRA_CA_CERTS` as this is only read once when launching Node.js - // and using `NODE_TLS_REJECT_UNAUTHORIZED` would apply globally and a warning is shown. - const tls = await import('node:tls'); - const originalConnect = tls.connect; - tls.connect = function (...args) { - if (args && typeof args === 'object') { - const options = args[0] as ConnectionOptions; - if (options.host === serverOptions.host && options.port == serverOptions.port) { - options.rejectUnauthorized = false; - } - } - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return originalConnect.apply(this, args as any); - }; - } } return configuration;