From 5fbc105ed0cb76106916660d99fc53d7480dcbc8 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 16 Dec 2024 17:05:27 +0000 Subject: [PATCH] fix(@angular/build): force HTTP/1.1 in dev-server SSR with SSL When server-side rendering (SSR) is enabled with SSL and Express, Vite must use HTTP/1.1 because Express does not support HTTP/2. This is achieved by setting an empty proxy configuration. Reference: https://github.com/vitejs/vite/blob/c4b532cc900bf988073583511f57bd581755d5e3/packages/vite/src/node/http.ts#L106 Closes #29142 (cherry picked from commit 19bb2d48097eaf8dcdbf584603210146b5f1b81e) --- .../build/src/builders/dev-server/vite-server.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/angular/build/src/builders/dev-server/vite-server.ts b/packages/angular/build/src/builders/dev-server/vite-server.ts index 04c0cf666b9f..9dfdfc5da39b 100644 --- a/packages/angular/build/src/builders/dev-server/vite-server.ts +++ b/packages/angular/build/src/builders/dev-server/vite-server.ts @@ -692,7 +692,15 @@ export async function setupServer( headers: serverOptions.headers, // Disable the websocket if live reload is disabled (false/undefined are the only valid values) ws: serverOptions.liveReload === false && serverOptions.hmr === false ? false : undefined, - proxy, + // When server-side rendering (SSR) is enabled togather with SSL and Express is being used, + // we must configure Vite to use HTTP/1.1. + // This is necessary because Express does not support HTTP/2. + // We achieve this by defining an empty proxy. + // See: https://github.com/vitejs/vite/blob/c4b532cc900bf988073583511f57bd581755d5e3/packages/vite/src/node/http.ts#L106 + proxy: + serverOptions.ssl && ssrMode === ServerSsrMode.ExternalSsrMiddleware + ? (proxy ?? {}) + : proxy, cors: { // Allow preflight requests to be proxied. preflightContinue: true,