diff --git a/packages/angular/build/src/utils/server-rendering/routes-extractor-worker.ts b/packages/angular/build/src/utils/server-rendering/routes-extractor-worker.ts index 5ea3ba5b2025..ebdba2c18b3a 100644 --- a/packages/angular/build/src/utils/server-rendering/routes-extractor-worker.ts +++ b/packages/angular/build/src/utils/server-rendering/routes-extractor-worker.ts @@ -26,10 +26,12 @@ const { outputMode, hasSsrEntry } = workerData as { hasSsrEntry: boolean; }; -let serverURL = DEFAULT_URL; - /** Renders an application based on a provided options. */ async function extractRoutes(): Promise { + const serverURL = outputMode !== undefined && hasSsrEntry ? await launchServer() : DEFAULT_URL; + + patchFetchToLoadInMemoryAssets(serverURL); + const { ɵextractRoutesAndCreateRouteTree: extractRoutesAndCreateRouteTree } = await loadEsmModuleFromMemory('./main.server.mjs'); @@ -47,14 +49,4 @@ async function extractRoutes(): Promise { }; } -async function initialize() { - if (outputMode !== undefined && hasSsrEntry) { - serverURL = await launchServer(); - } - - patchFetchToLoadInMemoryAssets(serverURL); - - return extractRoutes; -} - -export default initialize(); +export default extractRoutes;