From c9d4360000e6134b936781be3b0d5cf1871d44d7 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 21 Mar 2024 11:28:38 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): `Internal server error: Invalid URL` when using a non localhost IP When using a non-localhost IP, Vite will correctly populate the `network` property of the `server.resolvedUrls` instead of `local`. Example: ``` ng server --host=127.0.0.2 { local: [], network: [ 'http://127.0.0.2:4200/' ] } ``` Closes #27327 (cherry picked from commit ee9ec2301fd24972cf8de8b230e1ca088dbc0449) --- .../build_angular/src/tools/vite/angular-memory-plugin.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/build_angular/src/tools/vite/angular-memory-plugin.ts b/packages/angular_devkit/build_angular/src/tools/vite/angular-memory-plugin.ts index 3f7a8fa1f0b9..721424e34080 100644 --- a/packages/angular_devkit/build_angular/src/tools/vite/angular-memory-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/vite/angular-memory-plugin.ts @@ -219,9 +219,12 @@ export function createAngularMemoryPlugin(options: AngularMemoryPluginOptions): } transformIndexHtmlAndAddHeaders(req.url, rawHtml, res, next, async (html) => { + const resolvedUrls = server.resolvedUrls; + const baseUrl = resolvedUrls?.local[0] ?? resolvedUrls?.network[0]; + const { content } = await renderPage({ document: html, - route: new URL(req.originalUrl ?? '/', server.resolvedUrls?.local[0]).toString(), + route: new URL(req.originalUrl ?? '/', baseUrl).toString(), serverContext: 'ssr', loadBundle: (uri: string) => // eslint-disable-next-line @typescript-eslint/no-explicit-any