@@ -10,20 +10,45 @@ import { Hooks } from './hooks';
10
10
import { getPotentialLocaleIdFromUrl } from './i18n' ;
11
11
import { EntryPointExports , getAngularAppEngineManifest } from './manifest' ;
12
12
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
+
13
38
/**
14
39
* Angular server application engine.
15
40
* Manages Angular server applications (including localized ones), handles rendering requests,
16
41
* and optionally transforms index HTML before rendering.
17
42
*/
18
- export class AngularAppEngine {
43
+ export class AngularAppEngine implements AngularServerAppManager {
19
44
/**
20
45
* Hooks for extending or modifying the behavior of the server application.
21
46
* These hooks are used by the Angular CLI when running the development server and
22
47
* provide extensibility points for the application lifecycle.
23
48
*
24
- * @internal
49
+ * @private
25
50
*/
26
- static hooks = new Hooks ( ) ;
51
+ static ɵhooks = new Hooks ( ) ;
27
52
28
53
/**
29
54
* Provides access to the hooks for extending or modifying the server application's behavior.
@@ -32,7 +57,7 @@ export class AngularAppEngine {
32
57
* @internal
33
58
*/
34
59
get hooks ( ) : Hooks {
35
- return AngularAppEngine . hooks ;
60
+ return AngularAppEngine . ɵhooks ;
36
61
}
37
62
38
63
/**
@@ -92,3 +117,32 @@ export class AngularAppEngine {
92
117
return entryPoints . get ( potentialLocale ) ;
93
118
}
94
119
}
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