Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): `Internal server error: Invalid U…
Browse files Browse the repository at this point in the history
…RL` 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 ee9ec23)
  • Loading branch information
alan-agius4 authored and clydin committed Mar 21, 2024
1 parent 1a3257a commit c9d4360
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9d4360

Please sign in to comment.