Skip to content

Commit 5889d64

Browse files
committed
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 angular#26652
1 parent 8ccfffd commit 5889d64

File tree

1 file changed

+1
-23
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+1
-23
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

+1-23
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema';
3333
import { loadProxyConfiguration } from './load-proxy-config';
3434
import type { NormalizedDevServerOptions } from './options';
3535
import type { DevServerBuilderOutput } from './webpack-server';
36-
import { ConnectionOptions } from 'node:tls';
3736

3837
interface OutputFileRecord {
3938
contents: Uint8Array;
@@ -681,11 +680,9 @@ export async function setupServer(
681680
}
682681

683682
transformIndexHtmlAndAddHeaders(url, rawHtml, res, next, async (html) => {
684-
const url = new URL(req.originalUrl ?? '/', server.resolvedUrls?.local[0]);
685-
686683
const { content } = await renderPage({
687684
document: html,
688-
route: url.toString(),
685+
route: new URL(req.originalUrl ?? '/', server.resolvedUrls?.local[0]).toString(),
689686
serverContext: 'ssr',
690687
loadBundle: (uri: string) =>
691688
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -800,25 +797,6 @@ export async function setupServer(
800797
configuration.plugins ??= [];
801798
configuration.plugins.push(basicSslPlugin());
802799
}
803-
804-
if (ssr) {
805-
// Patch the TLS module to allow self signed certificate requests when running SSR.
806-
// We cannot use `NODE_EXTRA_CA_CERTS` as this is only read once when launching Node.js
807-
// and using `NODE_TLS_REJECT_UNAUTHORIZED` would apply globally and a warning is shown.
808-
const tls = await import('node:tls');
809-
const originalConnect = tls.connect;
810-
tls.connect = function (...args) {
811-
if (args && typeof args === 'object') {
812-
const options = args[0] as ConnectionOptions;
813-
if (options.host === serverOptions.host && options.port == serverOptions.port) {
814-
options.rejectUnauthorized = false;
815-
}
816-
}
817-
818-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
819-
return originalConnect.apply(this, args as any);
820-
};
821-
}
822800
}
823801

824802
return configuration;

0 commit comments

Comments
 (0)