@@ -10,20 +10,45 @@ import { Hooks } from './hooks';
1010import { getPotentialLocaleIdFromUrl } from './i18n' ;
1111import { EntryPointExports , getAngularAppEngineManifest } from './manifest' ;
1212
13+ /**
14+ * Angular server application engine.
15+ * Manages Angular server applications (including localized ones) and handles rendering requests.
16+
17+ * @developerPreview
18+ */
19+ export interface AngularServerAppManager {
20+ /**
21+ * Renders a response for the given HTTP request using the server application.
22+ *
23+ * This method processes the request, determines the appropriate route and rendering context,
24+ * and returns an HTTP response.
25+ *
26+ * If the request URL appears to be for a file (excluding `/index.html`), the method returns `null`.
27+ * A request to `https://www.example.com/page/index.html` will render the Angular route
28+ * corresponding to `https://www.example.com/page`.
29+ *
30+ * @param request - The incoming HTTP request object to be rendered.
31+ * @param requestContext - Optional additional context for the request, such as metadata.
32+ * @returns A promise that resolves to a Response object, or `null` if the request URL represents a file (e.g., `./logo.png`)
33+ * rather than an application route.
34+ */
35+ render ( request : Request , requestContext ?: unknown ) : Promise < Response | null > ;
36+ }
37+
1338/**
1439 * Angular server application engine.
1540 * Manages Angular server applications (including localized ones), handles rendering requests,
1641 * and optionally transforms index HTML before rendering.
1742 */
18- export class AngularAppEngine {
43+ export class AngularAppEngine implements AngularServerAppManager {
1944 /**
2045 * Hooks for extending or modifying the behavior of the server application.
2146 * These hooks are used by the Angular CLI when running the development server and
2247 * provide extensibility points for the application lifecycle.
2348 *
24- * @internal
49+ * @private
2550 */
26- static hooks = new Hooks ( ) ;
51+ static ɵhooks = new Hooks ( ) ;
2752
2853 /**
2954 * Provides access to the hooks for extending or modifying the server application's behavior.
@@ -32,7 +57,7 @@ export class AngularAppEngine {
3257 * @internal
3358 */
3459 get hooks ( ) : Hooks {
35- return AngularAppEngine . hooks ;
60+ return AngularAppEngine . ɵhooks ;
3661 }
3762
3863 /**
@@ -92,3 +117,32 @@ export class AngularAppEngine {
92117 return entryPoints . get ( potentialLocale ) ;
93118 }
94119}
120+
121+ let angularAppEngine : AngularAppEngine | undefined ;
122+
123+ /**
124+ * Retrieves an existing `AngularAppEngine` instance or creates a new one if none exists.
125+ *
126+ * This method ensures that only a single instance of `AngularAppEngine` is created and reused across
127+ * the application lifecycle, providing efficient resource management. If the instance does not exist,
128+ * it will be instantiated upon the first call.
129+ *
130+ * @developerPreview
131+ * @returns The existing or newly created instance of `AngularAppEngine`.
132+ */
133+ export function getOrCreateAngularAppEngine ( ) : AngularServerAppManager {
134+ return ( angularAppEngine ??= new AngularAppEngine ( ) ) ;
135+ }
136+
137+ /**
138+ * Destroys the current `AngularAppEngine` instance, releasing any associated resources.
139+ *
140+ * This method resets the reference to the `AngularAppEngine` instance to `undefined`, allowing
141+ * a new instance to be created on the next call to `getOrCreateAngularAppEngine()`. It is typically
142+ * used when reinitializing the server environment or refreshing the application state is necessary.
143+ *
144+ * @developerPreview
145+ */
146+ export function destroyAngularAppEngine ( ) : void {
147+ angularAppEngine = undefined ;
148+ }
0 commit comments