Skip to content

Commit 60ca3c8

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): provide server baseUrl result property 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)
1 parent 83b4b25 commit 60ca3c8

File tree

1 file changed

+10
-3
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+10
-3
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export async function* serveWithVite(
112112
const { createServer, normalizePath } = await import('vite');
113113

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

212212
await server.listen();
213-
listeningAddress = server.httpServer?.address() as AddressInfo;
213+
const urls = server.resolvedUrls;
214+
if (urls && (urls.local.length || urls.network.length)) {
215+
serverUrl = new URL(urls.local[0] ?? urls.network[0]);
216+
}
214217

215218
// log connection information
216219
server.printUrls();
217220
}
218221

219222
// TODO: adjust output typings to reflect both development servers
220-
yield { success: true, port: listeningAddress?.port } as unknown as DevServerBuilderOutput;
223+
yield {
224+
success: true,
225+
port: serverUrl?.port,
226+
baseUrl: serverUrl?.href,
227+
} as unknown as DevServerBuilderOutput;
221228
}
222229

223230
// Add cleanup logic via a builder teardown

0 commit comments

Comments
 (0)