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 angular#27327
  • Loading branch information
alan-agius4 committed Mar 21, 2024
1 parent d05f78b commit e9cab67
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

2 comments on commit e9cab67

@kirklimbu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do i solve this error? Thanks in advance :)

@alan-agius4
Copy link
Owner Author

@alan-agius4 alan-agius4 commented on e9cab67 Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’d need to wait for the next patch version release, which will happen mid next week.

Please sign in to comment.