Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): provide server baseUrl result pro…
Browse files Browse the repository at this point in the history
…perty in Vite-based dev server

The protractor E2E builder relies on a development server `baseUrl` result property to determine the address
to connect when testing the application. The Vite-based development server now also provides this
property. While the protractor builder is considered deprecated, it is still used in CLI E2E tests.

(cherry picked from commit 5b4f50c)
  • Loading branch information
clydin authored and alan-agius4 committed Nov 1, 2023
1 parent 83b4b25 commit 60ca3c8
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function* serveWithVite(
const { createServer, normalizePath } = await import('vite');

let server: ViteDevServer | undefined;
let listeningAddress: AddressInfo | undefined;
let serverUrl: URL | undefined;
let hadError = false;
const generatedFiles = new Map<string, OutputFileRecord>();
const assetFiles = new Map<string, string>();
Expand Down Expand Up @@ -210,14 +210,21 @@ export async function* serveWithVite(
server = await createServer(serverConfiguration);

await server.listen();
listeningAddress = server.httpServer?.address() as AddressInfo;
const urls = server.resolvedUrls;
if (urls && (urls.local.length || urls.network.length)) {
serverUrl = new URL(urls.local[0] ?? urls.network[0]);
}

// log connection information
server.printUrls();
}

// TODO: adjust output typings to reflect both development servers
yield { success: true, port: listeningAddress?.port } as unknown as DevServerBuilderOutput;
yield {
success: true,
port: serverUrl?.port,
baseUrl: serverUrl?.href,
} as unknown as DevServerBuilderOutput;
}

// Add cleanup logic via a builder teardown
Expand Down

0 comments on commit 60ca3c8

Please sign in to comment.