Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): construct SSR request URL using s…
Browse files Browse the repository at this point in the history
…erver resolvedUrls

With vite `header.host` is undefined when SSL is enabled. This resulted in an invalid URL to be constructed.

Closes angular#26652
  • Loading branch information
alan-agius4 committed Dec 13, 2023
1 parent 8ccfffd commit 5889d64
Showing 1 changed file with 1 addition and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5889d64

Please sign in to comment.