66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { AngularServerApp } from './app' ;
109import { Hooks } from './hooks' ;
1110import { getPotentialLocaleIdFromUrl } from './i18n' ;
12- import { getAngularAppEngineManifest } from './manifest' ;
11+ import { EntryPointExports , getAngularAppEngineManifest } from './manifest' ;
1312
1413/**
1514 * Angular server application engine.
@@ -19,43 +18,33 @@ import { getAngularAppEngineManifest } from './manifest';
1918export class AngularAppEngine {
2019 /**
2120 * Hooks for extending or modifying the behavior of the server application.
22- * @internal This property is accessed by the Angular CLI when running the dev-server.
21+ * These hooks are used by the Angular CLI when running the development server and
22+ * provide extensibility points for the application lifecycle.
23+ *
24+ * @internal
2325 */
2426 static hooks = new Hooks ( ) ;
2527
2628 /**
27- * Hooks for extending or modifying the behavior of the server application.
28- * This instance can be used to attach custom functionality to various events in the server application lifecycle.
29+ * Provides access to the hooks for extending or modifying the server application's behavior.
30+ * This allows attaching custom functionality to various server application lifecycle events.
31+ *
2932 * @internal
3033 */
3134 get hooks ( ) : Hooks {
3235 return AngularAppEngine . hooks ;
3336 }
3437
35- /**
36- * Specifies if the application is operating in development mode.
37- * This property controls the activation of features intended for production, such as caching mechanisms.
38- * @internal
39- */
40- static isDevMode = false ;
41-
4238 /**
4339 * The manifest for the server application.
4440 */
4541 private readonly manifest = getAngularAppEngineManifest ( ) ;
4642
4743 /**
48- * Map of locale strings to corresponding `AngularServerApp` instances.
49- * Each instance represents an Angular server application.
50- */
51- private readonly appsCache = new Map < string , AngularServerApp > ( ) ;
52-
53- /**
54- * Renders an HTTP request using the appropriate Angular server application and returns a response.
44+ * Renders a response for the given HTTP request using the server application.
5545 *
56- * This method determines the entry point for the Angular server application based on the request URL,
57- * and caches the server application instances for reuse. If the application is in development mode,
58- * the cache is bypassed and a new instance is created for each request.
46+ * This method processes the request, determines the appropriate route and rendering context,
47+ * and returns an HTTP response.
5948 *
6049 * If the request URL appears to be for a file (excluding `/index.html`), the method returns `null`.
6150 * A request to `https://www.example.com/page/index.html` will render the Angular route
@@ -69,25 +58,14 @@ export class AngularAppEngine {
6958 async render ( request : Request , requestContext ?: unknown ) : Promise < Response | null > {
7059 // Skip if the request looks like a file but not `/index.html`.
7160 const url = new URL ( request . url ) ;
72-
7361 const entryPoint = this . getEntryPointFromUrl ( url ) ;
7462 if ( ! entryPoint ) {
7563 return null ;
7664 }
7765
78- const [ locale , loadModule ] = entryPoint ;
79- let serverApp = this . appsCache . get ( locale ) ;
80- if ( ! serverApp ) {
81- const { AngularServerApp } = await loadModule ( ) ;
82- serverApp = new AngularServerApp ( {
83- isDevMode : AngularAppEngine . isDevMode ,
84- hooks : this . hooks ,
85- } ) ;
86-
87- if ( ! AngularAppEngine . isDevMode ) {
88- this . appsCache . set ( locale , serverApp ) ;
89- }
90- }
66+ const { ɵgetOrCreateAngularServerApp : getOrCreateAngularServerApp } = await entryPoint ( ) ;
67+ const serverApp = getOrCreateAngularServerApp ( ) ;
68+ serverApp . hooks = this . hooks ;
9169
9270 return serverApp . render ( request , requestContext ) ;
9371 }
@@ -99,30 +77,18 @@ export class AngularAppEngine {
9977 * If there is only one entry point available, it is returned regardless of the URL.
10078 * Otherwise, the method extracts a potential locale identifier from the URL and looks up the corresponding entry point.
10179 *
102- * @param url - The URL used to derive the locale and determine the entry point.
103- * @returns An array containing:
104- * - The first element is the locale extracted from the URL.
105- * - The second element is a function that returns a promise resolving to an object with the `AngularServerApp` type.
106- *
107- * Returns `null` if no matching entry point is found for the extracted locale.
80+ * @param url - The URL used to derive the locale and determine the appropriate entry point.
81+ * @returns A function that returns a promise resolving to an object with the `EntryPointExports` type,
82+ * or `undefined` if no matching entry point is found for the extracted locale.
10883 */
109- private getEntryPointFromUrl ( url : URL ) :
110- | [
111- locale : string ,
112- loadModule : ( ) => Promise < {
113- AngularServerApp : typeof AngularServerApp ;
114- } > ,
115- ]
116- | null {
117- // Find bundle for locale
84+ private getEntryPointFromUrl ( url : URL ) : ( ( ) => Promise < EntryPointExports > ) | undefined {
11885 const { entryPoints, basePath } = this . manifest ;
11986 if ( entryPoints . size === 1 ) {
120- return entryPoints . entries ( ) . next ( ) . value ;
87+ return entryPoints . values ( ) . next ( ) . value ;
12188 }
12289
12390 const potentialLocale = getPotentialLocaleIdFromUrl ( url , basePath ) ;
124- const entryPoint = entryPoints . get ( potentialLocale ) ;
12591
126- return entryPoint ? [ potentialLocale , entryPoint ] : null ;
92+ return entryPoints . get ( potentialLocale ) ;
12793 }
12894}
0 commit comments