6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
+ import { workerData } from 'worker_threads' ;
9
10
import { OutputMode } from '../../builders/application/schema' ;
11
+ import { ESMInMemoryFileLoaderWorkerData } from './esm-in-memory-loader/loader-hooks' ;
10
12
import { patchFetchToLoadInMemoryAssets } from './fetch-patch' ;
13
+ import { DEFAULT_URL , launchServer } from './launch-server' ;
11
14
import { loadEsmModuleFromMemory } from './load-esm-from-memory' ;
12
15
import { RoutersExtractorWorkerResult } from './models' ;
13
16
14
- export interface ExtractRoutesOptions {
15
- outputMode ? : OutputMode ;
17
+ export interface ExtractRoutesWorkerData extends ESMInMemoryFileLoaderWorkerData {
18
+ outputMode : OutputMode | undefined ;
16
19
}
17
20
21
+ /**
22
+ * This is passed as workerData when setting up the worker via the `piscina` package.
23
+ */
24
+ const { outputMode, hasSsrEntry } = workerData as {
25
+ outputMode : OutputMode | undefined ;
26
+ hasSsrEntry : boolean ;
27
+ } ;
28
+
29
+ let serverURL = DEFAULT_URL ;
30
+
18
31
/** Renders an application based on a provided options. */
19
- async function extractRoutes ( {
20
- outputMode,
21
- } : ExtractRoutesOptions ) : Promise < RoutersExtractorWorkerResult > {
32
+ async function extractRoutes ( ) : Promise < RoutersExtractorWorkerResult > {
22
33
const { ɵextractRoutesAndCreateRouteTree : extractRoutesAndCreateRouteTree } =
23
34
await loadEsmModuleFromMemory ( './main.server.mjs' ) ;
24
35
25
36
const { routeTree, errors } = await extractRoutesAndCreateRouteTree (
26
- new URL ( 'http://local-angular-prerender/' ) ,
37
+ serverURL ,
27
38
undefined /** manifest */ ,
28
39
true /** invokeGetPrerenderParams */ ,
29
40
outputMode === OutputMode . Server /** includePrerenderFallbackRoutes */ ,
@@ -35,8 +46,12 @@ async function extractRoutes({
35
46
} ;
36
47
}
37
48
38
- function initialize ( ) {
39
- patchFetchToLoadInMemoryAssets ( ) ;
49
+ async function initialize ( ) {
50
+ if ( outputMode !== undefined && hasSsrEntry ) {
51
+ serverURL = await launchServer ( ) ;
52
+ }
53
+
54
+ patchFetchToLoadInMemoryAssets ( serverURL ) ;
40
55
41
56
return extractRoutes ;
42
57
}
0 commit comments