@angular/ssr 19.2.8 → 19.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,401 +1,427 @@
1
- import type { ApplicationRef } from '@angular/core';
2
- import { default as default_2 } from 'beasties';
1
+ import { EnvironmentProviders, Type, Provider, ApplicationRef } from '@angular/core';
3
2
  import { DefaultExport } from '@angular/router';
4
- import { EnvironmentProviders } from '@angular/core';
5
- import { Provider } from '@angular/core';
6
- import { Type } from '@angular/core';
3
+ import Beasties from './third_party/beasties';
7
4
 
8
5
  /**
9
- * Angular server application engine.
10
- * Manages Angular server applications (including localized ones), handles rendering requests,
11
- * and optionally transforms index HTML before rendering.
12
- *
13
- * @remarks This class should be instantiated once and used as a singleton across the server-side
14
- * application to ensure consistent handling of rendering requests and resource management.
15
- *
6
+ * Identifies a particular kind of `ServerRoutesFeatureKind`.
7
+ * @see {@link ServerRoutesFeature}
16
8
  * @developerPreview
17
9
  */
18
- export declare class AngularAppEngine {
19
- /**
20
- * A flag to enable or disable the rendering of prerendered routes.
21
- *
22
- * Typically used during development to avoid prerendering all routes ahead of time,
23
- * allowing them to be rendered on the fly as requested.
24
- *
25
- * @private
26
- */
27
- static ɵallowStaticRouteRender: boolean;
28
- /**
29
- * Hooks for extending or modifying the behavior of the server application.
30
- * These hooks are used by the Angular CLI when running the development server and
31
- * provide extensibility points for the application lifecycle.
32
- *
33
- * @private
34
- */
35
- static ɵhooks: Hooks;
10
+ declare enum ServerRoutesFeatureKind {
11
+ AppShell = 0
12
+ }
13
+ /**
14
+ * Helper type to represent a server routes feature.
15
+ * @see {@link ServerRoutesFeatureKind}
16
+ * @developerPreview
17
+ */
18
+ interface ServerRoutesFeature<FeatureKind extends ServerRoutesFeatureKind> {
19
+ ɵkind: FeatureKind;
20
+ ɵproviders: Provider[];
21
+ }
22
+ /**
23
+ * Different rendering modes for server routes.
24
+ * @see {@link provideServerRouting}
25
+ * @see {@link ServerRoute}
26
+ * @developerPreview
27
+ */
28
+ declare enum RenderMode {
29
+ /** Server-Side Rendering (SSR) mode, where content is rendered on the server for each request. */
30
+ Server = 0,
31
+ /** Client-Side Rendering (CSR) mode, where content is rendered on the client side in the browser. */
32
+ Client = 1,
33
+ /** Static Site Generation (SSG) mode, where content is pre-rendered at build time and served as static files. */
34
+ Prerender = 2
35
+ }
36
+ /**
37
+ * Defines the fallback strategies for Static Site Generation (SSG) routes when a pre-rendered path is not available.
38
+ * This is particularly relevant for routes with parameterized URLs where some paths might not be pre-rendered at build time.
39
+ * @see {@link ServerRoutePrerenderWithParams}
40
+ * @developerPreview
41
+ */
42
+ declare enum PrerenderFallback {
36
43
  /**
37
- * The manifest for the server application.
44
+ * Fallback to Server-Side Rendering (SSR) if the pre-rendered path is not available.
45
+ * This strategy dynamically generates the page on the server at request time.
38
46
  */
39
- private readonly manifest;
47
+ Server = 0,
40
48
  /**
41
- * A map of supported locales from the server application's manifest.
49
+ * Fallback to Client-Side Rendering (CSR) if the pre-rendered path is not available.
50
+ * This strategy allows the page to be rendered on the client side.
42
51
  */
43
- private readonly supportedLocales;
52
+ Client = 1,
44
53
  /**
45
- * A cache that holds entry points, keyed by their potential locale string.
54
+ * No fallback; if the path is not pre-rendered, the server will not handle the request.
55
+ * This means the application will not provide any response for paths that are not pre-rendered.
46
56
  */
47
- private readonly entryPointsCache;
57
+ None = 2
58
+ }
59
+ /**
60
+ * Common interface for server routes, providing shared properties.
61
+ * @developerPreview
62
+ */
63
+ interface ServerRouteCommon {
64
+ /** The path associated with this route. */
65
+ path: string;
66
+ /** Optional additional headers to include in the response for this route. */
67
+ headers?: Record<string, string>;
68
+ /** Optional status code to return for this route. */
69
+ status?: number;
70
+ }
71
+ /**
72
+ * A server route that uses Client-Side Rendering (CSR) mode.
73
+ * @see {@link RenderMode}
74
+ * @developerPreview
75
+ */
76
+ interface ServerRouteClient extends ServerRouteCommon {
77
+ /** Specifies that the route uses Client-Side Rendering (CSR) mode. */
78
+ renderMode: RenderMode.Client;
79
+ }
80
+ /**
81
+ * A server route that uses Static Site Generation (SSG) mode.
82
+ * @see {@link RenderMode}
83
+ * @developerPreview
84
+ */
85
+ interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'> {
86
+ /** Specifies that the route uses Static Site Generation (SSG) mode. */
87
+ renderMode: RenderMode.Prerender;
88
+ /** Fallback cannot be specified unless `getPrerenderParams` is used. */
89
+ fallback?: never;
90
+ }
91
+ /**
92
+ * A server route configuration that uses Static Site Generation (SSG) mode, including support for routes with parameters.
93
+ * @see {@link RenderMode}
94
+ * @see {@link ServerRoutePrerender}
95
+ * @see {@link PrerenderFallback}
96
+ * @developerPreview
97
+ */
98
+ interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerender, 'fallback'> {
48
99
  /**
49
- * Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
50
- * or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
51
- *
52
- * @param request - The HTTP request to handle.
53
- * @param requestContext - Optional context for rendering, such as metadata associated with the request.
54
- * @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
100
+ * Optional strategy to use if the SSG path is not pre-rendered.
101
+ * This is especially relevant for routes with parameterized URLs, where some paths may not be pre-rendered at build time.
55
102
  *
56
- * @remarks A request to `https://www.example.com/page/index.html` will serve or render the Angular route
57
- * corresponding to `https://www.example.com/page`.
58
- */
59
- handle(request: Request, requestContext?: unknown): Promise<Response | null>;
60
- /**
61
- * Handles requests for the base path when i18n is enabled.
62
- * Redirects the user to a locale-specific path based on the `Accept-Language` header.
103
+ * This property determines how to handle requests for paths that are not pre-rendered:
104
+ * - `PrerenderFallback.Server`: Use Server-Side Rendering (SSR) to dynamically generate the page at request time.
105
+ * - `PrerenderFallback.Client`: Use Client-Side Rendering (CSR) to fetch and render the page on the client side.
106
+ * - `PrerenderFallback.None`: No fallback; if the path is not pre-rendered, the server will not handle the request.
63
107
  *
64
- * @param request The incoming request.
65
- * @returns A `Response` object with a 302 redirect, or `null` if i18n is not enabled
66
- * or the request is not for the base path.
108
+ * @default `PrerenderFallback.Server` if not provided.
67
109
  */
68
- private redirectBasedOnAcceptLanguage;
110
+ fallback?: PrerenderFallback;
69
111
  /**
70
- * Retrieves the Angular server application instance for a given request.
71
- *
72
- * This method checks if the request URL corresponds to an Angular application entry point.
73
- * If so, it initializes or retrieves an instance of the Angular server application for that entry point.
74
- * Requests that resemble file requests (except for `/index.html`) are skipped.
112
+ * A function that returns a Promise resolving to an array of objects, each representing a route path with URL parameters.
113
+ * This function runs in the injector context, allowing access to Angular services and dependencies.
75
114
  *
76
- * @param request - The incoming HTTP request object.
77
- * @returns A promise that resolves to an `AngularServerApp` instance if a valid entry point is found,
78
- * or `null` if no entry point matches the request URL.
79
- */
80
- private getAngularServerAppForRequest;
81
- /**
82
- * Retrieves the exports for a specific entry point, caching the result.
115
+ * It also works for catch-all routes (e.g., `/**`), where the parameter name will be `**` and the return value will be
116
+ * the segments of the path, such as `/foo/bar`. These routes can also be combined, e.g., `/product/:id/**`,
117
+ * where both a parameterized segment (`:id`) and a catch-all segment (`**`) can be used together to handle more complex paths.
83
118
  *
84
- * @param potentialLocale - The locale string used to find the corresponding entry point.
85
- * @returns A promise that resolves to the entry point exports or `undefined` if not found.
86
- */
87
- private getEntryPointExports;
88
- /**
89
- * Retrieves the entry point for a given URL by determining the locale and mapping it to
90
- * the appropriate application bundle.
119
+ * @returns A Promise resolving to an array where each element is an object with string keys (representing URL parameter names)
120
+ * and string values (representing the corresponding values for those parameters in the route path).
91
121
  *
92
- * This method determines the appropriate entry point and locale for rendering the application by examining the URL.
93
- * If there is only one entry point available, it is returned regardless of the URL.
94
- * Otherwise, the method extracts a potential locale identifier from the URL and looks up the corresponding entry point.
122
+ * @example
123
+ * ```typescript
124
+ * export const serverRouteConfig: ServerRoutes[] = [
125
+ * {
126
+ * path: '/product/:id',
127
+ * renderMode: RenderMode.Prerender,
128
+ * async getPrerenderParams() {
129
+ * const productService = inject(ProductService);
130
+ * const ids = await productService.getIds(); // Assuming this returns ['1', '2', '3']
95
131
  *
96
- * @param url - The URL of the request.
97
- * @returns A promise that resolves to the entry point exports or `undefined` if not found.
132
+ * return ids.map(id => ({ id })); // Generates paths like: ['product/1', 'product/2', 'product/3']
133
+ * },
134
+ * },
135
+ * {
136
+ * path: '/product/:id/**',
137
+ * renderMode: RenderMode.Prerender,
138
+ * async getPrerenderParams() {
139
+ * return [
140
+ * { id: '1', '**': 'laptop/3' },
141
+ * { id: '2', '**': 'laptop/4' }
142
+ * ]; // Generates paths like: ['product/1/laptop/3', 'product/2/laptop/4']
143
+ * },
144
+ * },
145
+ * ];
146
+ * ```
98
147
  */
99
- private getEntryPointExportsForUrl;
148
+ getPrerenderParams: () => Promise<Record<string, string>[]>;
100
149
  }
101
-
102
150
  /**
103
- * Manifest for the Angular server application engine, defining entry points.
151
+ * A server route that uses Server-Side Rendering (SSR) mode.
152
+ * @see {@link RenderMode}
153
+ * @developerPreview
104
154
  */
105
- declare interface AngularAppEngineManifest {
106
- /**
107
- * A readonly record of entry points for the server application.
108
- * Each entry consists of:
109
- * - `key`: The url segment for the entry point.
110
- * - `value`: A function that returns a promise resolving to an object of type `EntryPointExports`.
111
- */
112
- readonly entryPoints: Readonly<Record<string, (() => Promise<EntryPointExports>) | undefined>>;
113
- /**
114
- * The base path for the server application.
115
- * This is used to determine the root path of the application.
116
- */
117
- readonly basePath: string;
118
- /**
119
- * A readonly record mapping supported locales to their respective entry-point paths.
120
- * Each entry consists of:
121
- * - `key`: The locale identifier (e.g., 'en', 'fr').
122
- * - `value`: The url segment associated with that locale.
123
- */
124
- readonly supportedLocales: Readonly<Record<string, string | undefined>>;
155
+ interface ServerRouteServer extends ServerRouteCommon {
156
+ /** Specifies that the route uses Server-Side Rendering (SSR) mode. */
157
+ renderMode: RenderMode.Server;
125
158
  }
126
-
127
159
  /**
128
- * Manifest for a specific Angular server application, defining assets and bootstrap logic.
160
+ * Server route configuration.
161
+ * @see {@link provideServerRouting}
162
+ * @developerPreview
129
163
  */
130
- declare interface AngularAppManifest {
131
- /**
132
- * The base href for the application.
133
- * This is used to determine the root path of the application.
134
- */
135
- readonly baseHref: string;
136
- /**
137
- * A readonly record of assets required by the server application.
138
- * Each entry consists of:
139
- * - `key`: The path of the asset.
140
- * - `value`: An object of type `ServerAsset`.
141
- */
142
- readonly assets: Readonly<Record<string, ServerAsset | undefined>>;
143
- /**
144
- * The bootstrap mechanism for the server application.
145
- * A function that returns a promise that resolves to an `NgModule` or a function
146
- * returning a promise that resolves to an `ApplicationRef`.
147
- */
148
- readonly bootstrap: () => Promise<AngularBootstrap>;
149
- /**
150
- * Indicates whether critical CSS should be inlined into the HTML.
151
- * If set to `true`, critical CSS will be inlined for faster page rendering.
152
- */
153
- readonly inlineCriticalCss?: boolean;
154
- /**
155
- * The route tree representation for the routing configuration of the application.
156
- * This represents the routing information of the application, mapping route paths to their corresponding metadata.
157
- * It is used for route matching and navigation within the server application.
158
- */
159
- readonly routes?: SerializableRouteTreeNode;
160
- /**
161
- * An optional string representing the locale or language code to be used for
162
- * the application, aiding with localization and rendering content specific to the locale.
163
- */
164
- readonly locale?: string;
164
+ type ServerRoute = ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer;
165
+ /**
166
+ * Configuration options for server routes.
167
+ *
168
+ * This interface defines the optional settings available for configuring server routes
169
+ * in the server-side environment, such as specifying a path to the app shell route.
170
+ *
171
+ *
172
+ * @see {@link provideServerRouting}
173
+ * @deprecated use `provideServerRouting`. This will be removed in version 20.
174
+ */
175
+ interface ServerRoutesConfigOptions {
165
176
  /**
166
- * Maps entry-point names to their corresponding browser bundles and loading strategies.
167
- *
168
- * - **Key**: The entry-point name, typically the value of `ɵentryName`.
169
- * - **Value**: An array of objects, each representing a browser bundle with:
170
- * - `path`: The filename or URL of the associated JavaScript bundle to preload.
171
- * - `dynamicImport`: A boolean indicating whether the bundle is loaded via a dynamic `import()`.
172
- * If `true`, the bundle is lazily loaded, impacting its preloading behavior.
173
- *
174
- * ### Example
175
- * ```ts
176
- * {
177
- * 'src/app/lazy/lazy.ts': [{ path: 'src/app/lazy/lazy.js', dynamicImport: true }]
178
- * }
179
- * ```
177
+ * Defines the route to be used as the app shell, which serves as the main entry
178
+ * point for the application. This route is often used to enable server-side rendering
179
+ * of the application shell for requests that do not match any specific server route.
180
180
  */
181
- readonly entryPointToBrowserMapping?: Readonly<Record<string, ReadonlyArray<{
182
- path: string;
183
- dynamicImport: boolean;
184
- }> | undefined>>;
181
+ appShellRoute?: string;
185
182
  }
186
-
187
183
  /**
188
- * Represents the bootstrap mechanism for an Angular application.
184
+ * Sets up the necessary providers for configuring server routes.
185
+ * This function accepts an array of server routes and optional configuration
186
+ * options, returning an `EnvironmentProviders` object that encapsulates
187
+ * the server routes and configuration settings.
189
188
  *
190
- * This type can either be:
191
- * - A reference to an Angular component or module (`Type<unknown>`) that serves as the root of the application.
192
- * - A function that returns a `Promise<ApplicationRef>`, which resolves with the root application reference.
189
+ * @param routes - An array of server routes to be provided.
190
+ * @param options - (Optional) An object containing additional configuration options for server routes.
191
+ * @returns An `EnvironmentProviders` instance with the server routes configuration.
192
+ *
193
+ * @see {@link ServerRoute}
194
+ * @see {@link ServerRoutesConfigOptions}
195
+ * @see {@link provideServerRouting}
196
+ * @deprecated use `provideServerRouting`. This will be removed in version 20.
197
+ * @developerPreview
198
+ */
199
+ declare function provideServerRoutesConfig(routes: ServerRoute[], options?: ServerRoutesConfigOptions): EnvironmentProviders;
200
+ /**
201
+ * Sets up the necessary providers for configuring server routes.
202
+ * This function accepts an array of server routes and optional configuration
203
+ * options, returning an `EnvironmentProviders` object that encapsulates
204
+ * the server routes and configuration settings.
205
+ *
206
+ * @param routes - An array of server routes to be provided.
207
+ * @param features - (Optional) server routes features.
208
+ * @returns An `EnvironmentProviders` instance with the server routes configuration.
209
+ *
210
+ * @see {@link ServerRoute}
211
+ * @see {@link withAppShell}
212
+ * @developerPreview
213
+ */
214
+ declare function provideServerRouting(routes: ServerRoute[], ...features: ServerRoutesFeature<ServerRoutesFeatureKind>[]): EnvironmentProviders;
215
+ /**
216
+ * Configures the app shell route with the provided component.
217
+ *
218
+ * The app shell serves as the main entry point for the application and is commonly used
219
+ * to enable server-side rendering (SSR) of the application shell. It handles requests
220
+ * that do not match any specific server route, providing a fallback mechanism and improving
221
+ * perceived performance during navigation.
222
+ *
223
+ * This configuration is particularly useful in applications leveraging Progressive Web App (PWA)
224
+ * patterns, such as service workers, to deliver a seamless user experience.
225
+ *
226
+ * @param component The Angular component to render for the app shell route.
227
+ * @returns A server routes feature configuration for the app shell.
228
+ *
229
+ * @see {@link provideServerRouting}
230
+ * @see {@link https://angular.dev/ecosystem/service-workers/app-shell | App shell pattern on Angular.dev}
193
231
  */
194
- declare type AngularBootstrap = Type<unknown> | (() => Promise<ApplicationRef>);
232
+ declare function withAppShell(component: Type<unknown> | (() => Promise<Type<unknown> | DefaultExport<Type<unknown>>>)): ServerRoutesFeature<ServerRoutesFeatureKind.AppShell>;
195
233
 
196
234
  /**
197
- * Result of extracting routes from an Angular application.
235
+ * Represents the serialized format of a route tree as an array of node metadata objects.
236
+ * Each entry in the array corresponds to a specific node's metadata within the route tree.
237
+ */
238
+ type SerializableRouteTreeNode = ReadonlyArray<RouteTreeNodeMetadata>;
239
+ /**
240
+ * Represents metadata for a route tree node, excluding the 'route' path segment.
241
+ */
242
+ type RouteTreeNodeMetadataWithoutRoute = Omit<RouteTreeNodeMetadata, 'route'>;
243
+ /**
244
+ * Describes metadata associated with a node in the route tree.
245
+ * This metadata includes information such as the route path and optional redirect instructions.
198
246
  */
199
- declare interface AngularRouterConfigResult {
247
+ interface RouteTreeNodeMetadata {
200
248
  /**
201
- * The base URL for the application.
202
- * This is the base href that is used for resolving relative paths within the application.
249
+ * Optional redirect path associated with this node.
250
+ * This defines where to redirect if this route is matched.
203
251
  */
204
- baseHref: string;
252
+ redirectTo?: string;
205
253
  /**
206
- * An array of `RouteTreeNodeMetadata` objects representing the application's routes.
254
+ * The route path for this node.
207
255
  *
208
- * Each `RouteTreeNodeMetadata` contains details about a specific route, such as its path and any
209
- * associated redirection targets. This array is asynchronously generated and
210
- * provides information on how routes are structured and resolved.
211
- */
212
- routes: RouteTreeNodeMetadata[];
213
- /**
214
- * Optional configuration for server routes.
256
+ * A "route" is a URL path or pattern that is used to navigate to different parts of a web application.
257
+ * It is made up of one or more segments separated by slashes `/`. For instance, in the URL `/products/details/42`,
258
+ * the full route is `/products/details/42`, with segments `products`, `details`, and `42`.
215
259
  *
216
- * This property allows you to specify an array of server routes for configuration.
217
- * If not provided, the default configuration or behavior will be used.
218
- */
219
- serverRoutesConfig?: ServerRoute[] | null;
220
- /**
221
- * A list of errors encountered during the route extraction process.
260
+ * Routes define how URLs map to views or components in an application. Each route segment contributes to
261
+ * the overall path that determines which view or component is displayed.
262
+ *
263
+ * - **Static Routes**: These routes have fixed segments. For example, `/about` or `/contact`.
264
+ * - **Parameterized Routes**: These include dynamic segments that act as placeholders, such as `/users/:id`,
265
+ * where `:id` could be any user ID.
266
+ *
267
+ * In the context of `RouteTreeNodeMetadata`, the `route` property represents the complete path that this node
268
+ * in the route tree corresponds to. This path is used to determine how a specific URL in the browser maps to the
269
+ * structure and content of the application.
222
270
  */
223
- errors: string[];
271
+ route: string;
224
272
  /**
225
- * The specified route for the app-shell, if configured.
273
+ * Optional status code to return for this route.
226
274
  */
227
- appShellRoute?: string;
228
- }
229
-
230
- /**
231
- * Represents a locale-specific Angular server application managed by the server application engine.
232
- *
233
- * The `AngularServerApp` class handles server-side rendering and asset management for a specific locale.
234
- */
235
- declare class AngularServerApp {
236
- private readonly options;
275
+ status?: number;
237
276
  /**
238
- * Whether prerendered routes should be rendered on demand or served directly.
239
- *
240
- * @see {@link AngularServerAppOptions.allowStaticRouteRender} for more details.
277
+ * Optional additional headers to include in the response for this route.
241
278
  */
242
- private readonly allowStaticRouteRender;
279
+ headers?: Record<string, string>;
243
280
  /**
244
- * Hooks for extending or modifying server behavior.
245
- *
246
- * @see {@link AngularServerAppOptions.hooks} for more details.
281
+ * Specifies the rendering mode used for this route.
247
282
  */
248
- readonly hooks: Hooks;
283
+ renderMode: RenderMode;
249
284
  /**
250
- * Constructs an instance of `AngularServerApp`.
251
- *
252
- * @param options Optional configuration options for the server application.
285
+ * A list of resource that should be preloaded by the browser.
253
286
  */
254
- constructor(options?: Readonly<AngularServerAppOptions>);
287
+ preload?: readonly string[];
288
+ }
289
+ /**
290
+ * Represents a node within the route tree structure.
291
+ * Each node corresponds to a route segment and may have associated metadata and child nodes.
292
+ * The `AdditionalMetadata` type parameter allows for extending the node metadata with custom data.
293
+ */
294
+ interface RouteTreeNode<AdditionalMetadata extends Record<string, unknown>> {
255
295
  /**
256
- * The manifest associated with this server application.
296
+ * A map of child nodes, keyed by their corresponding route segment or wildcard.
257
297
  */
258
- private readonly manifest;
298
+ children: Map<string, RouteTreeNode<AdditionalMetadata>>;
259
299
  /**
260
- * An instance of ServerAsset that handles server-side asset.
300
+ * Optional metadata associated with this node, providing additional information such as redirects.
261
301
  */
262
- private readonly assets;
302
+ metadata?: RouteTreeNodeMetadata & AdditionalMetadata;
303
+ }
304
+ /**
305
+ * A route tree implementation that supports efficient route matching, including support for wildcard routes.
306
+ * This structure is useful for organizing and retrieving routes in a hierarchical manner,
307
+ * enabling complex routing scenarios with nested paths.
308
+ *
309
+ * @typeParam AdditionalMetadata - Type of additional metadata that can be associated with route nodes.
310
+ */
311
+ declare class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}> {
263
312
  /**
264
- * The router instance used for route matching and handling.
313
+ * The root node of the route tree.
314
+ * All routes are stored and accessed relative to this root node.
265
315
  */
266
- private router;
316
+ private readonly root;
267
317
  /**
268
- * The `inlineCriticalCssProcessor` is responsible for handling critical CSS inlining.
318
+ * Inserts a new route into the route tree.
319
+ * The route is broken down into segments, and each segment is added to the tree.
320
+ * Parameterized segments (e.g., :id) are normalized to wildcards (*) for matching purposes.
321
+ *
322
+ * @param route - The route path to insert into the tree.
323
+ * @param metadata - Metadata associated with the route, excluding the route path itself.
269
324
  */
270
- private inlineCriticalCssProcessor;
325
+ insert(route: string, metadata: RouteTreeNodeMetadataWithoutRoute & AdditionalMetadata): void;
271
326
  /**
272
- * The bootstrap mechanism for the server application.
327
+ * Matches a given route against the route tree and returns the best matching route's metadata.
328
+ * The best match is determined by the lowest insertion index, meaning the earliest defined route
329
+ * takes precedence.
330
+ *
331
+ * @param route - The route path to match against the route tree.
332
+ * @returns The metadata of the best matching route or `undefined` if no match is found.
273
333
  */
274
- private boostrap;
334
+ match(route: string): (RouteTreeNodeMetadata & AdditionalMetadata) | undefined;
275
335
  /**
276
- * Cache for storing critical CSS for pages.
277
- * Stores a maximum of MAX_INLINE_CSS_CACHE_ENTRIES entries.
336
+ * Converts the route tree into a serialized format representation.
337
+ * This method converts the route tree into an array of metadata objects that describe the structure of the tree.
338
+ * The array represents the routes in a nested manner where each entry includes the route and its associated metadata.
278
339
  *
279
- * Uses an LRU (Least Recently Used) eviction policy, meaning that when the cache is full,
280
- * the least recently accessed page's critical CSS will be removed to make space for new entries.
340
+ * @returns An array of `RouteTreeNodeMetadata` objects representing the route tree structure.
341
+ * Each object includes the `route` and associated metadata of a route.
281
342
  */
282
- private readonly criticalCssLRUCache;
343
+ toObject(): SerializableRouteTreeNode;
283
344
  /**
284
- * Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
285
- * or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
286
- *
287
- * @param request - The HTTP request to handle.
288
- * @param requestContext - Optional context for rendering, such as metadata associated with the request.
289
- * @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
345
+ * Constructs a `RouteTree` from an object representation.
346
+ * This method is used to recreate a `RouteTree` instance from an array of metadata objects.
347
+ * The array should be in the format produced by `toObject`, allowing for the reconstruction of the route tree
348
+ * with the same routes and metadata.
290
349
  *
291
- * @remarks A request to `https://www.example.com/page/index.html` will serve or render the Angular route
292
- * corresponding to `https://www.example.com/page`.
350
+ * @param value - An array of `RouteTreeNodeMetadata` objects that represent the serialized format of the route tree.
351
+ * Each object should include a `route` and its associated metadata.
352
+ * @returns A new `RouteTree` instance constructed from the provided metadata objects.
293
353
  */
294
- handle(request: Request, requestContext?: unknown): Promise<Response | null>;
354
+ static fromObject(value: SerializableRouteTreeNode): RouteTree;
295
355
  /**
296
- * Handles serving a prerendered static asset if available for the matched route.
297
- *
298
- * This method only supports `GET` and `HEAD` requests.
356
+ * A generator function that recursively traverses the route tree and yields the metadata of each node.
357
+ * This allows for easy and efficient iteration over all nodes in the tree.
299
358
  *
300
- * @param request - The incoming HTTP request for serving a static page.
301
- * @param matchedRoute - The metadata of the matched route for rendering.
302
- * If not provided, the method attempts to find a matching route based on the request URL.
303
- * @returns A promise that resolves to a `Response` object if the prerendered page is found, or `null`.
359
+ * @param node - The current node to start the traversal from. Defaults to the root node of the tree.
304
360
  */
305
- private handleServe;
361
+ traverse(node?: RouteTreeNode<AdditionalMetadata>): Generator<RouteTreeNodeMetadata & AdditionalMetadata>;
306
362
  /**
307
- * Handles the server-side rendering process for the given HTTP request.
308
- * This method matches the request URL to a route and performs rendering if a matching route is found.
309
- *
310
- * @param request - The incoming HTTP request to be processed.
311
- * @param matchedRoute - The metadata of the matched route for rendering.
312
- * If not provided, the method attempts to find a matching route based on the request URL.
313
- * @param requestContext - Optional additional context for rendering, such as request metadata.
363
+ * Extracts the path segments from a given route string.
314
364
  *
315
- * @returns A promise that resolves to the rendered response, or null if no matching route is found.
365
+ * @param route - The route string from which to extract segments.
366
+ * @returns An array of path segments.
316
367
  */
317
- private handleRendering;
368
+ private getPathSegments;
318
369
  /**
319
- * Constructs the asset path on the server based on the provided HTTP request.
370
+ * Recursively traverses the route tree from a given node, attempting to match the remaining route segments.
371
+ * If the node is a leaf node (no more segments to match) and contains metadata, the node is yielded.
320
372
  *
321
- * This method processes the incoming request URL to derive a path corresponding
322
- * to the requested asset. It ensures the path points to the correct file (e.g.,
323
- * `index.html`) and removes any base href if it is not part of the asset path.
373
+ * This function prioritizes exact segment matches first, followed by wildcard matches (`*`),
374
+ * and finally deep wildcard matches (`**`) that consume all segments.
324
375
  *
325
- * @param request - The incoming HTTP request object.
326
- * @returns The server-relative asset path derived from the request.
376
+ * @param segments - The array of route path segments to match against the route tree.
377
+ * @param node - The current node in the route tree to start traversal from. Defaults to the root node.
378
+ * @param currentIndex - The index of the segment in `remainingSegments` currently being matched.
379
+ * Defaults to `0` (the first segment).
380
+ *
381
+ * @returns The node that best matches the remaining segments or `undefined` if no match is found.
327
382
  */
328
- private buildServerAssetPathFromRequest;
383
+ private traverseBySegments;
329
384
  /**
330
- * Runs the registered transform hooks on the given HTML content.
385
+ * Creates an empty route tree node.
386
+ * This helper function is used during the tree construction.
331
387
  *
332
- * @param html - The raw HTML content to be transformed.
333
- * @param url - The URL associated with the HTML content, used for context during transformations.
334
- * @param preload - An array of URLs representing the JavaScript resources to preload.
335
- * @returns A promise that resolves to the transformed HTML string.
388
+ * @returns A new, empty route tree node.
336
389
  */
337
- private runTransformsOnHtml;
390
+ private createEmptyRouteTreeNode;
338
391
  }
339
392
 
340
393
  /**
341
- * Options for configuring an `AngularServerApp`.
394
+ * Represents the bootstrap mechanism for an Angular application.
395
+ *
396
+ * This type can either be:
397
+ * - A reference to an Angular component or module (`Type<unknown>`) that serves as the root of the application.
398
+ * - A function that returns a `Promise<ApplicationRef>`, which resolves with the root application reference.
399
+ */
400
+ type AngularBootstrap = Type<unknown> | (() => Promise<ApplicationRef>);
401
+
402
+ /**
403
+ * Represents a server asset stored in the manifest.
342
404
  */
343
- declare interface AngularServerAppOptions {
405
+ interface ServerAsset {
344
406
  /**
345
- * Whether to allow rendering of prerendered routes.
346
- *
347
- * When enabled, prerendered routes will be served directly. When disabled, they will be
348
- * rendered on demand.
407
+ * Retrieves the text content of the asset.
349
408
  *
350
- * Defaults to `false`.
409
+ * @returns A promise that resolves to the asset's content as a string.
351
410
  */
352
- allowStaticRouteRender?: boolean;
411
+ text: () => Promise<string>;
353
412
  /**
354
- * Hooks for extending or modifying server behavior.
355
- *
356
- * This allows customization of the server's rendering process and other lifecycle events.
357
- *
358
- * If not provided, a new `Hooks` instance is created.
413
+ * A hash string representing the asset's content.
359
414
  */
360
- hooks?: Hooks;
361
- }
362
-
363
- declare interface BeastiesBase {
364
- embedLinkedStylesheet(link: PartialHTMLElement, document: PartialDocument): Promise<unknown>;
365
- }
366
-
367
- declare class BeastiesBase extends default_2 {
415
+ hash: string;
416
+ /**
417
+ * The size of the asset's content in bytes.
418
+ */
419
+ size: number;
368
420
  }
369
-
370
- /**
371
- * Annotates a request handler function with metadata, marking it as a special
372
- * handler.
373
- *
374
- * @param handler - The request handler function to be annotated.
375
- * @returns The same handler function passed in, with metadata attached.
376
- *
377
- * @example
378
- * Example usage in a Hono application:
379
- * ```ts
380
- * const app = new Hono();
381
- * export default createRequestHandler(app.fetch);
382
- * ```
383
- *
384
- * @example
385
- * Example usage in a H3 application:
386
- * ```ts
387
- * const app = createApp();
388
- * const handler = toWebHandler(app);
389
- * export default createRequestHandler(handler);
390
- * ```
391
- * @developerPreview
392
- */
393
- export declare function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction;
394
-
395
421
  /**
396
422
  * Represents the exports of an Angular server application entry point.
397
423
  */
398
- declare interface EntryPointExports {
424
+ interface EntryPointExports {
399
425
  /**
400
426
  * A reference to the function that creates an Angular server application instance.
401
427
  *
@@ -407,563 +433,382 @@ declare interface EntryPointExports {
407
433
  */
408
434
  ɵdestroyAngularServerApp: () => void;
409
435
  }
410
-
411
- declare type EntryPointToBrowserMapping = AngularAppManifest['entryPointToBrowserMapping'];
412
-
413
436
  /**
414
- * Defines the names of available hooks for registering and triggering custom logic within the application.
437
+ * Manifest for the Angular server application engine, defining entry points.
415
438
  */
416
- declare type HookName = keyof HooksMapping;
417
-
439
+ interface AngularAppEngineManifest {
440
+ /**
441
+ * A readonly record of entry points for the server application.
442
+ * Each entry consists of:
443
+ * - `key`: The url segment for the entry point.
444
+ * - `value`: A function that returns a promise resolving to an object of type `EntryPointExports`.
445
+ */
446
+ readonly entryPoints: Readonly<Record<string, (() => Promise<EntryPointExports>) | undefined>>;
447
+ /**
448
+ * The base path for the server application.
449
+ * This is used to determine the root path of the application.
450
+ */
451
+ readonly basePath: string;
452
+ /**
453
+ * A readonly record mapping supported locales to their respective entry-point paths.
454
+ * Each entry consists of:
455
+ * - `key`: The locale identifier (e.g., 'en', 'fr').
456
+ * - `value`: The url segment associated with that locale.
457
+ */
458
+ readonly supportedLocales: Readonly<Record<string, string | undefined>>;
459
+ }
418
460
  /**
419
- * Manages a collection of hooks and provides methods to register and execute them.
420
- * Hooks are functions that can be invoked with specific arguments to allow modifications or enhancements.
461
+ * Manifest for a specific Angular server application, defining assets and bootstrap logic.
421
462
  */
422
- declare class Hooks {
463
+ interface AngularAppManifest {
423
464
  /**
424
- * A map of hook names to arrays of hook functions.
425
- * Each hook name can have multiple associated functions, which are executed in sequence.
465
+ * The base href for the application.
466
+ * This is used to determine the root path of the application.
426
467
  */
427
- private readonly store;
468
+ readonly baseHref: string;
428
469
  /**
429
- * Registers a new hook function under the specified hook name.
430
- * This function should be a function that takes an argument of type `T` and returns a `string` or `Promise<string>`.
431
- *
432
- * @template Hook - The type of the hook name. It should be one of the keys of `HooksMapping`.
433
- * @param name - The name of the hook under which the function will be registered.
434
- * @param handler - A function to be executed when the hook is triggered. The handler will be called with an argument
435
- * that may be modified by the hook functions.
436
- *
437
- * @remarks
438
- * - If there are existing handlers registered under the given hook name, the new handler will be added to the list.
439
- * - If no handlers are registered under the given hook name, a new list will be created with the handler as its first element.
440
- *
441
- * @example
442
- * ```typescript
443
- * hooks.on('html:transform:pre', async (ctx) => {
444
- * return ctx.html.replace(/foo/g, 'bar');
445
- * });
446
- * ```
470
+ * A readonly record of assets required by the server application.
471
+ * Each entry consists of:
472
+ * - `key`: The path of the asset.
473
+ * - `value`: An object of type `ServerAsset`.
447
474
  */
448
- on<Hook extends HookName>(name: Hook, handler: HooksMapping[Hook]): void;
475
+ readonly assets: Readonly<Record<string, ServerAsset | undefined>>;
449
476
  /**
450
- * Checks if there are any hooks registered under the specified name.
477
+ * The bootstrap mechanism for the server application.
478
+ * A function that returns a promise that resolves to an `NgModule` or a function
479
+ * returning a promise that resolves to an `ApplicationRef`.
480
+ */
481
+ readonly bootstrap: () => Promise<AngularBootstrap>;
482
+ /**
483
+ * Indicates whether critical CSS should be inlined into the HTML.
484
+ * If set to `true`, critical CSS will be inlined for faster page rendering.
485
+ */
486
+ readonly inlineCriticalCss?: boolean;
487
+ /**
488
+ * The route tree representation for the routing configuration of the application.
489
+ * This represents the routing information of the application, mapping route paths to their corresponding metadata.
490
+ * It is used for route matching and navigation within the server application.
491
+ */
492
+ readonly routes?: SerializableRouteTreeNode;
493
+ /**
494
+ * An optional string representing the locale or language code to be used for
495
+ * the application, aiding with localization and rendering content specific to the locale.
496
+ */
497
+ readonly locale?: string;
498
+ /**
499
+ * Maps entry-point names to their corresponding browser bundles and loading strategies.
451
500
  *
452
- * @param name - The name of the hook to check.
453
- * @returns `true` if there are hooks registered under the specified name, otherwise `false`.
501
+ * - **Key**: The entry-point name, typically the value of `ɵentryName`.
502
+ * - **Value**: An array of objects, each representing a browser bundle with:
503
+ * - `path`: The filename or URL of the associated JavaScript bundle to preload.
504
+ * - `dynamicImport`: A boolean indicating whether the bundle is loaded via a dynamic `import()`.
505
+ * If `true`, the bundle is lazily loaded, impacting its preloading behavior.
506
+ *
507
+ * ### Example
508
+ * ```ts
509
+ * {
510
+ * 'src/app/lazy/lazy.ts': [{ path: 'src/app/lazy/lazy.js', dynamicImport: true }]
511
+ * }
512
+ * ```
454
513
  */
455
- has(name: HookName): boolean;
514
+ readonly entryPointToBrowserMapping?: Readonly<Record<string, ReadonlyArray<{
515
+ path: string;
516
+ dynamicImport: boolean;
517
+ }> | undefined>>;
456
518
  }
457
-
458
519
  /**
459
- * Mapping of hook names to their corresponding handler types.
520
+ * Sets the Angular app manifest.
521
+ *
522
+ * @param manifest - The manifest object to set for the Angular application.
460
523
  */
461
- declare interface HooksMapping {
462
- 'html:transform:pre': HtmlTransformHandler;
463
- }
464
-
465
-
524
+ declare function setAngularAppManifest(manifest: AngularAppManifest): void;
466
525
  /**
467
- * Defines a handler function type for transforming HTML content.
468
- * This function receives an object with the HTML to be processed.
526
+ * Sets the Angular app engine manifest.
469
527
  *
470
- * @param ctx - An object containing the URL and HTML content to be transformed.
471
- * @returns The transformed HTML as a string or a promise that resolves to the transformed HTML.
528
+ * @param manifest - The engine manifest object to set.
472
529
  */
473
- declare type HtmlTransformHandler = (ctx: {
474
- url: URL;
475
- html: string;
476
- }) => string | Promise<string>;
477
-
478
- /** Partial representation of an HTML `Document`. */
479
- declare interface PartialDocument {
480
- head: PartialHTMLElement;
481
- createElement(tagName: string): PartialHTMLElement;
482
- querySelector(selector: string): PartialHTMLElement | null;
483
- }
484
-
485
- /** Partial representation of an `HTMLElement`. */
486
- declare interface PartialHTMLElement {
487
- getAttribute(name: string): string | null;
488
- setAttribute(name: string, value: string): void;
489
- hasAttribute(name: string): boolean;
490
- removeAttribute(name: string): void;
491
- appendChild(child: PartialHTMLElement): void;
492
- insertBefore(newNode: PartialHTMLElement, referenceNode?: PartialHTMLElement): void;
493
- remove(): void;
494
- name: string;
495
- textContent: string;
496
- tagName: string | null;
497
- children: PartialHTMLElement[];
498
- next: PartialHTMLElement | null;
499
- prev: PartialHTMLElement | null;
500
- }
530
+ declare function setAngularAppEngineManifest(manifest: AngularAppEngineManifest): void;
501
531
 
502
532
  /**
503
- * Defines the fallback strategies for Static Site Generation (SSG) routes when a pre-rendered path is not available.
504
- * This is particularly relevant for routes with parameterized URLs where some paths might not be pre-rendered at build time.
505
- * @see {@link ServerRoutePrerenderWithParams}
506
- * @developerPreview
533
+ * Result of extracting routes from an Angular application.
507
534
  */
508
- export declare enum PrerenderFallback {
535
+ interface AngularRouterConfigResult {
509
536
  /**
510
- * Fallback to Server-Side Rendering (SSR) if the pre-rendered path is not available.
511
- * This strategy dynamically generates the page on the server at request time.
537
+ * The base URL for the application.
538
+ * This is the base href that is used for resolving relative paths within the application.
512
539
  */
513
- Server = 0,
540
+ baseHref: string;
514
541
  /**
515
- * Fallback to Client-Side Rendering (CSR) if the pre-rendered path is not available.
516
- * This strategy allows the page to be rendered on the client side.
542
+ * An array of `RouteTreeNodeMetadata` objects representing the application's routes.
543
+ *
544
+ * Each `RouteTreeNodeMetadata` contains details about a specific route, such as its path and any
545
+ * associated redirection targets. This array is asynchronously generated and
546
+ * provides information on how routes are structured and resolved.
517
547
  */
518
- Client = 1,
548
+ routes: RouteTreeNodeMetadata[];
519
549
  /**
520
- * No fallback; if the path is not pre-rendered, the server will not handle the request.
521
- * This means the application will not provide any response for paths that are not pre-rendered.
550
+ * Optional configuration for server routes.
551
+ *
552
+ * This property allows you to specify an array of server routes for configuration.
553
+ * If not provided, the default configuration or behavior will be used.
522
554
  */
523
- None = 2
555
+ serverRoutesConfig?: ServerRoute[] | null;
556
+ /**
557
+ * A list of errors encountered during the route extraction process.
558
+ */
559
+ errors: string[];
560
+ /**
561
+ * The specified route for the app-shell, if configured.
562
+ */
563
+ appShellRoute?: string;
524
564
  }
525
-
565
+ type EntryPointToBrowserMapping = AngularAppManifest['entryPointToBrowserMapping'];
526
566
  /**
527
- * Sets up the necessary providers for configuring server routes.
528
- * This function accepts an array of server routes and optional configuration
529
- * options, returning an `EnvironmentProviders` object that encapsulates
530
- * the server routes and configuration settings.
567
+ * Retrieves routes from the given Angular application.
531
568
  *
532
- * @param routes - An array of server routes to be provided.
533
- * @param options - (Optional) An object containing additional configuration options for server routes.
534
- * @returns An `EnvironmentProviders` instance with the server routes configuration.
569
+ * This function initializes an Angular platform, bootstraps the application or module,
570
+ * and retrieves routes from the Angular router configuration. It handles both module-based
571
+ * and function-based bootstrapping. It yields the resulting routes as `RouteTreeNodeMetadata` objects or errors.
535
572
  *
536
- * @see {@link ServerRoute}
537
- * @see {@link ServerRoutesConfigOptions}
538
- * @see {@link provideServerRouting}
539
- * @deprecated use `provideServerRouting`. This will be removed in version 20.
540
- * @developerPreview
573
+ * @param bootstrap - A function that returns a promise resolving to an `ApplicationRef` or an Angular module to bootstrap.
574
+ * @param document - The initial HTML document used for server-side rendering.
575
+ * This document is necessary to render the application on the server.
576
+ * @param url - The URL for server-side rendering. The URL is used to configure `ServerPlatformLocation`. This configuration is crucial
577
+ * for ensuring that API requests for relative paths succeed, which is essential for accurate route extraction.
578
+ * @param invokeGetPrerenderParams - A boolean flag indicating whether to invoke `getPrerenderParams` for parameterized SSG routes
579
+ * to handle prerendering paths. Defaults to `false`.
580
+ * @param includePrerenderFallbackRoutes - A flag indicating whether to include fallback routes in the result. Defaults to `true`.
581
+ * @param entryPointToBrowserMapping - Maps the entry-point name to the associated JavaScript browser bundles.
582
+ *
583
+ * @returns A promise that resolves to an object of type `AngularRouterConfigResult` or errors.
541
584
  */
542
- export declare function provideServerRoutesConfig(routes: ServerRoute[], options?: ServerRoutesConfigOptions): EnvironmentProviders;
543
-
585
+ declare function getRoutesFromAngularRouterConfig(bootstrap: AngularBootstrap, document: string, url: URL, invokeGetPrerenderParams?: boolean, includePrerenderFallbackRoutes?: boolean, entryPointToBrowserMapping?: EntryPointToBrowserMapping | undefined): Promise<AngularRouterConfigResult>;
544
586
  /**
545
- * Sets up the necessary providers for configuring server routes.
546
- * This function accepts an array of server routes and optional configuration
547
- * options, returning an `EnvironmentProviders` object that encapsulates
548
- * the server routes and configuration settings.
587
+ * Asynchronously extracts routes from the Angular application configuration
588
+ * and creates a `RouteTree` to manage server-side routing.
549
589
  *
550
- * @param routes - An array of server routes to be provided.
551
- * @param features - (Optional) server routes features.
552
- * @returns An `EnvironmentProviders` instance with the server routes configuration.
590
+ * @param options - An object containing the following options:
591
+ * - `url`: The URL for server-side rendering. The URL is used to configure `ServerPlatformLocation`. This configuration is crucial
592
+ * for ensuring that API requests for relative paths succeed, which is essential for accurate route extraction.
593
+ * See:
594
+ * - https://github.com/angular/angular/blob/d608b857c689d17a7ffa33bbb510301014d24a17/packages/platform-server/src/location.ts#L51
595
+ * - https://github.com/angular/angular/blob/6882cc7d9eed26d3caeedca027452367ba25f2b9/packages/platform-server/src/http.ts#L44
596
+ * - `manifest`: An optional `AngularAppManifest` that contains the application's routing and configuration details.
597
+ * If not provided, the default manifest is retrieved using `getAngularAppManifest()`.
598
+ * - `invokeGetPrerenderParams`: A boolean flag indicating whether to invoke `getPrerenderParams` for parameterized SSG routes
599
+ * to handle prerendering paths. Defaults to `false`.
600
+ * - `includePrerenderFallbackRoutes`: A flag indicating whether to include fallback routes in the result. Defaults to `true`.
601
+ * - `signal`: An optional `AbortSignal` that can be used to abort the operation.
553
602
  *
554
- * @see {@link ServerRoute}
555
- * @see {@link withAppShell}
556
- * @developerPreview
603
+ * @returns A promise that resolves to an object containing:
604
+ * - `routeTree`: A populated `RouteTree` containing all extracted routes from the Angular application.
605
+ * - `appShellRoute`: The specified route for the app-shell, if configured.
606
+ * - `errors`: An array of strings representing any errors encountered during the route extraction process.
557
607
  */
558
- export declare function provideServerRouting(routes: ServerRoute[], ...features: ServerRoutesFeature<ServerRoutesFeatureKind>[]): EnvironmentProviders;
608
+ declare function extractRoutesAndCreateRouteTree(options: {
609
+ url: URL;
610
+ manifest?: AngularAppManifest;
611
+ invokeGetPrerenderParams?: boolean;
612
+ includePrerenderFallbackRoutes?: boolean;
613
+ signal?: AbortSignal;
614
+ }): Promise<{
615
+ routeTree: RouteTree;
616
+ appShellRoute?: string;
617
+ errors: string[];
618
+ }>;
559
619
 
560
620
  /**
561
- * Different rendering modes for server routes.
562
- * @see {@link provideServerRouting}
563
- * @see {@link ServerRoute}
564
- * @developerPreview
621
+ * Defines a handler function type for transforming HTML content.
622
+ * This function receives an object with the HTML to be processed.
623
+ *
624
+ * @param ctx - An object containing the URL and HTML content to be transformed.
625
+ * @returns The transformed HTML as a string or a promise that resolves to the transformed HTML.
565
626
  */
566
- export declare enum RenderMode {
567
- /** Server-Side Rendering (SSR) mode, where content is rendered on the server for each request. */
568
- Server = 0,
569
- /** Client-Side Rendering (CSR) mode, where content is rendered on the client side in the browser. */
570
- Client = 1,
571
- /** Static Site Generation (SSG) mode, where content is pre-rendered at build time and served as static files. */
572
- Prerender = 2
573
- }
574
-
575
-
627
+ type HtmlTransformHandler = (ctx: {
628
+ url: URL;
629
+ html: string;
630
+ }) => string | Promise<string>;
576
631
  /**
577
- * Function for handling HTTP requests in a web environment.
578
- *
579
- * @param request - The incoming HTTP request object.
580
- * @returns A Promise resolving to a `Response` object, `null`, or directly a `Response`,
581
- * supporting both synchronous and asynchronous handling.
582
- * @developerPreview
632
+ * Defines the names of available hooks for registering and triggering custom logic within the application.
583
633
  */
584
- export declare type RequestHandlerFunction = (request: Request) => Promise<Response | null> | null | Response;
585
-
634
+ type HookName = keyof HooksMapping;
586
635
  /**
587
- * A route tree implementation that supports efficient route matching, including support for wildcard routes.
588
- * This structure is useful for organizing and retrieving routes in a hierarchical manner,
589
- * enabling complex routing scenarios with nested paths.
590
- *
591
- * @typeParam AdditionalMetadata - Type of additional metadata that can be associated with route nodes.
636
+ * Mapping of hook names to their corresponding handler types.
592
637
  */
593
- declare class RouteTree<AdditionalMetadata extends Record<string, unknown> = {}> {
594
- /**
595
- * The root node of the route tree.
596
- * All routes are stored and accessed relative to this root node.
597
- */
598
- private readonly root;
599
- /**
600
- * Inserts a new route into the route tree.
601
- * The route is broken down into segments, and each segment is added to the tree.
602
- * Parameterized segments (e.g., :id) are normalized to wildcards (*) for matching purposes.
603
- *
604
- * @param route - The route path to insert into the tree.
605
- * @param metadata - Metadata associated with the route, excluding the route path itself.
606
- */
607
- insert(route: string, metadata: RouteTreeNodeMetadataWithoutRoute & AdditionalMetadata): void;
608
- /**
609
- * Matches a given route against the route tree and returns the best matching route's metadata.
610
- * The best match is determined by the lowest insertion index, meaning the earliest defined route
611
- * takes precedence.
612
- *
613
- * @param route - The route path to match against the route tree.
614
- * @returns The metadata of the best matching route or `undefined` if no match is found.
615
- */
616
- match(route: string): (RouteTreeNodeMetadata & AdditionalMetadata) | undefined;
617
- /**
618
- * Converts the route tree into a serialized format representation.
619
- * This method converts the route tree into an array of metadata objects that describe the structure of the tree.
620
- * The array represents the routes in a nested manner where each entry includes the route and its associated metadata.
621
- *
622
- * @returns An array of `RouteTreeNodeMetadata` objects representing the route tree structure.
623
- * Each object includes the `route` and associated metadata of a route.
624
- */
625
- toObject(): SerializableRouteTreeNode;
626
- /**
627
- * Constructs a `RouteTree` from an object representation.
628
- * This method is used to recreate a `RouteTree` instance from an array of metadata objects.
629
- * The array should be in the format produced by `toObject`, allowing for the reconstruction of the route tree
630
- * with the same routes and metadata.
631
- *
632
- * @param value - An array of `RouteTreeNodeMetadata` objects that represent the serialized format of the route tree.
633
- * Each object should include a `route` and its associated metadata.
634
- * @returns A new `RouteTree` instance constructed from the provided metadata objects.
635
- */
636
- static fromObject(value: SerializableRouteTreeNode): RouteTree;
637
- /**
638
- * A generator function that recursively traverses the route tree and yields the metadata of each node.
639
- * This allows for easy and efficient iteration over all nodes in the tree.
640
- *
641
- * @param node - The current node to start the traversal from. Defaults to the root node of the tree.
642
- */
643
- traverse(node?: RouteTreeNode<AdditionalMetadata>): Generator<RouteTreeNodeMetadata & AdditionalMetadata>;
638
+ interface HooksMapping {
639
+ 'html:transform:pre': HtmlTransformHandler;
640
+ }
641
+ /**
642
+ * Manages a collection of hooks and provides methods to register and execute them.
643
+ * Hooks are functions that can be invoked with specific arguments to allow modifications or enhancements.
644
+ */
645
+ declare class Hooks {
644
646
  /**
645
- * Extracts the path segments from a given route string.
646
- *
647
- * @param route - The route string from which to extract segments.
648
- * @returns An array of path segments.
647
+ * A map of hook names to arrays of hook functions.
648
+ * Each hook name can have multiple associated functions, which are executed in sequence.
649
649
  */
650
- private getPathSegments;
650
+ private readonly store;
651
651
  /**
652
- * Recursively traverses the route tree from a given node, attempting to match the remaining route segments.
653
- * If the node is a leaf node (no more segments to match) and contains metadata, the node is yielded.
652
+ * Registers a new hook function under the specified hook name.
653
+ * This function should be a function that takes an argument of type `T` and returns a `string` or `Promise<string>`.
654
654
  *
655
- * This function prioritizes exact segment matches first, followed by wildcard matches (`*`),
656
- * and finally deep wildcard matches (`**`) that consume all segments.
655
+ * @template Hook - The type of the hook name. It should be one of the keys of `HooksMapping`.
656
+ * @param name - The name of the hook under which the function will be registered.
657
+ * @param handler - A function to be executed when the hook is triggered. The handler will be called with an argument
658
+ * that may be modified by the hook functions.
657
659
  *
658
- * @param segments - The array of route path segments to match against the route tree.
659
- * @param node - The current node in the route tree to start traversal from. Defaults to the root node.
660
- * @param currentIndex - The index of the segment in `remainingSegments` currently being matched.
661
- * Defaults to `0` (the first segment).
660
+ * @remarks
661
+ * - If there are existing handlers registered under the given hook name, the new handler will be added to the list.
662
+ * - If no handlers are registered under the given hook name, a new list will be created with the handler as its first element.
662
663
  *
663
- * @returns The node that best matches the remaining segments or `undefined` if no match is found.
664
+ * @example
665
+ * ```typescript
666
+ * hooks.on('html:transform:pre', async (ctx) => {
667
+ * return ctx.html.replace(/foo/g, 'bar');
668
+ * });
669
+ * ```
664
670
  */
665
- private traverseBySegments;
671
+ on<Hook extends HookName>(name: Hook, handler: HooksMapping[Hook]): void;
666
672
  /**
667
- * Creates an empty route tree node.
668
- * This helper function is used during the tree construction.
673
+ * Checks if there are any hooks registered under the specified name.
669
674
  *
670
- * @returns A new, empty route tree node.
675
+ * @param name - The name of the hook to check.
676
+ * @returns `true` if there are hooks registered under the specified name, otherwise `false`.
671
677
  */
672
- private createEmptyRouteTreeNode;
678
+ has(name: HookName): boolean;
673
679
  }
674
680
 
675
681
  /**
676
- * Represents a node within the route tree structure.
677
- * Each node corresponds to a route segment and may have associated metadata and child nodes.
678
- * The `AdditionalMetadata` type parameter allows for extending the node metadata with custom data.
682
+ * Options for configuring an `AngularServerApp`.
679
683
  */
680
- declare interface RouteTreeNode<AdditionalMetadata extends Record<string, unknown>> {
684
+ interface AngularServerAppOptions {
681
685
  /**
682
- * A map of child nodes, keyed by their corresponding route segment or wildcard.
686
+ * Whether to allow rendering of prerendered routes.
687
+ *
688
+ * When enabled, prerendered routes will be served directly. When disabled, they will be
689
+ * rendered on demand.
690
+ *
691
+ * Defaults to `false`.
683
692
  */
684
- children: Map<string, RouteTreeNode<AdditionalMetadata>>;
693
+ allowStaticRouteRender?: boolean;
685
694
  /**
686
- * Optional metadata associated with this node, providing additional information such as redirects.
695
+ * Hooks for extending or modifying server behavior.
696
+ *
697
+ * This allows customization of the server's rendering process and other lifecycle events.
698
+ *
699
+ * If not provided, a new `Hooks` instance is created.
687
700
  */
688
- metadata?: RouteTreeNodeMetadata & AdditionalMetadata;
701
+ hooks?: Hooks;
689
702
  }
690
-
691
703
  /**
692
- * Describes metadata associated with a node in the route tree.
693
- * This metadata includes information such as the route path and optional redirect instructions.
704
+ * Represents a locale-specific Angular server application managed by the server application engine.
705
+ *
706
+ * The `AngularServerApp` class handles server-side rendering and asset management for a specific locale.
694
707
  */
695
- declare interface RouteTreeNodeMetadata {
708
+ declare class AngularServerApp {
709
+ private readonly options;
696
710
  /**
697
- * Optional redirect path associated with this node.
698
- * This defines where to redirect if this route is matched.
711
+ * Whether prerendered routes should be rendered on demand or served directly.
712
+ *
713
+ * @see {@link AngularServerAppOptions.allowStaticRouteRender} for more details.
699
714
  */
700
- redirectTo?: string;
715
+ private readonly allowStaticRouteRender;
701
716
  /**
702
- * The route path for this node.
703
- *
704
- * A "route" is a URL path or pattern that is used to navigate to different parts of a web application.
705
- * It is made up of one or more segments separated by slashes `/`. For instance, in the URL `/products/details/42`,
706
- * the full route is `/products/details/42`, with segments `products`, `details`, and `42`.
707
- *
708
- * Routes define how URLs map to views or components in an application. Each route segment contributes to
709
- * the overall path that determines which view or component is displayed.
717
+ * Hooks for extending or modifying server behavior.
710
718
  *
711
- * - **Static Routes**: These routes have fixed segments. For example, `/about` or `/contact`.
712
- * - **Parameterized Routes**: These include dynamic segments that act as placeholders, such as `/users/:id`,
713
- * where `:id` could be any user ID.
719
+ * @see {@link AngularServerAppOptions.hooks} for more details.
720
+ */
721
+ readonly hooks: Hooks;
722
+ /**
723
+ * Constructs an instance of `AngularServerApp`.
714
724
  *
715
- * In the context of `RouteTreeNodeMetadata`, the `route` property represents the complete path that this node
716
- * in the route tree corresponds to. This path is used to determine how a specific URL in the browser maps to the
717
- * structure and content of the application.
725
+ * @param options Optional configuration options for the server application.
718
726
  */
719
- route: string;
727
+ constructor(options?: Readonly<AngularServerAppOptions>);
720
728
  /**
721
- * Optional status code to return for this route.
729
+ * The manifest associated with this server application.
722
730
  */
723
- status?: number;
731
+ private readonly manifest;
724
732
  /**
725
- * Optional additional headers to include in the response for this route.
733
+ * An instance of ServerAsset that handles server-side asset.
726
734
  */
727
- headers?: Record<string, string>;
735
+ private readonly assets;
728
736
  /**
729
- * Specifies the rendering mode used for this route.
737
+ * The router instance used for route matching and handling.
730
738
  */
731
- renderMode: RenderMode;
739
+ private router;
732
740
  /**
733
- * A list of resource that should be preloaded by the browser.
741
+ * The `inlineCriticalCssProcessor` is responsible for handling critical CSS inlining.
734
742
  */
735
- preload?: readonly string[];
736
- }
737
-
738
- /**
739
- * Represents metadata for a route tree node, excluding the 'route' path segment.
740
- */
741
- declare type RouteTreeNodeMetadataWithoutRoute = Omit<RouteTreeNodeMetadata, 'route'>;
742
-
743
- /**
744
- * Represents the serialized format of a route tree as an array of node metadata objects.
745
- * Each entry in the array corresponds to a specific node's metadata within the route tree.
746
- */
747
- declare type SerializableRouteTreeNode = ReadonlyArray<RouteTreeNodeMetadata>;
748
-
749
- /**
750
- * Represents a server asset stored in the manifest.
751
- */
752
- declare interface ServerAsset {
743
+ private inlineCriticalCssProcessor;
753
744
  /**
754
- * Retrieves the text content of the asset.
755
- *
756
- * @returns A promise that resolves to the asset's content as a string.
745
+ * The bootstrap mechanism for the server application.
757
746
  */
758
- text: () => Promise<string>;
747
+ private boostrap;
759
748
  /**
760
- * A hash string representing the asset's content.
749
+ * Cache for storing critical CSS for pages.
750
+ * Stores a maximum of MAX_INLINE_CSS_CACHE_ENTRIES entries.
751
+ *
752
+ * Uses an LRU (Least Recently Used) eviction policy, meaning that when the cache is full,
753
+ * the least recently accessed page's critical CSS will be removed to make space for new entries.
761
754
  */
762
- hash: string;
755
+ private readonly criticalCssLRUCache;
763
756
  /**
764
- * The size of the asset's content in bytes.
757
+ * Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
758
+ * or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
759
+ *
760
+ * @param request - The HTTP request to handle.
761
+ * @param requestContext - Optional context for rendering, such as metadata associated with the request.
762
+ * @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
763
+ *
764
+ * @remarks A request to `https://www.example.com/page/index.html` will serve or render the Angular route
765
+ * corresponding to `https://www.example.com/page`.
765
766
  */
766
- size: number;
767
- }
768
-
769
- /**
770
- * Server route configuration.
771
- * @see {@link provideServerRouting}
772
- * @developerPreview
773
- */
774
- export declare type ServerRoute = ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer;
775
-
776
- /**
777
- * A server route that uses Client-Side Rendering (CSR) mode.
778
- * @see {@link RenderMode}
779
- * @developerPreview
780
- */
781
- export declare interface ServerRouteClient extends ServerRouteCommon {
782
- /** Specifies that the route uses Client-Side Rendering (CSR) mode. */
783
- renderMode: RenderMode.Client;
784
- }
785
-
786
- /**
787
- * Common interface for server routes, providing shared properties.
788
- * @developerPreview
789
- */
790
- export declare interface ServerRouteCommon {
791
- /** The path associated with this route. */
792
- path: string;
793
- /** Optional additional headers to include in the response for this route. */
794
- headers?: Record<string, string>;
795
- /** Optional status code to return for this route. */
796
- status?: number;
797
- }
798
-
799
- /**
800
- * A server route that uses Static Site Generation (SSG) mode.
801
- * @see {@link RenderMode}
802
- * @developerPreview
803
- */
804
- export declare interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'> {
805
- /** Specifies that the route uses Static Site Generation (SSG) mode. */
806
- renderMode: RenderMode.Prerender;
807
- /** Fallback cannot be specified unless `getPrerenderParams` is used. */
808
- fallback?: never;
809
- }
810
-
811
- /**
812
- * A server route configuration that uses Static Site Generation (SSG) mode, including support for routes with parameters.
813
- * @see {@link RenderMode}
814
- * @see {@link ServerRoutePrerender}
815
- * @see {@link PrerenderFallback}
816
- * @developerPreview
817
- */
818
- export declare interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerender, 'fallback'> {
767
+ handle(request: Request, requestContext?: unknown): Promise<Response | null>;
819
768
  /**
820
- * Optional strategy to use if the SSG path is not pre-rendered.
821
- * This is especially relevant for routes with parameterized URLs, where some paths may not be pre-rendered at build time.
769
+ * Handles serving a prerendered static asset if available for the matched route.
822
770
  *
823
- * This property determines how to handle requests for paths that are not pre-rendered:
824
- * - `PrerenderFallback.Server`: Use Server-Side Rendering (SSR) to dynamically generate the page at request time.
825
- * - `PrerenderFallback.Client`: Use Client-Side Rendering (CSR) to fetch and render the page on the client side.
826
- * - `PrerenderFallback.None`: No fallback; if the path is not pre-rendered, the server will not handle the request.
771
+ * This method only supports `GET` and `HEAD` requests.
827
772
  *
828
- * @default `PrerenderFallback.Server` if not provided.
773
+ * @param request - The incoming HTTP request for serving a static page.
774
+ * @param matchedRoute - The metadata of the matched route for rendering.
775
+ * If not provided, the method attempts to find a matching route based on the request URL.
776
+ * @returns A promise that resolves to a `Response` object if the prerendered page is found, or `null`.
829
777
  */
830
- fallback?: PrerenderFallback;
778
+ private handleServe;
831
779
  /**
832
- * A function that returns a Promise resolving to an array of objects, each representing a route path with URL parameters.
833
- * This function runs in the injector context, allowing access to Angular services and dependencies.
780
+ * Handles the server-side rendering process for the given HTTP request.
781
+ * This method matches the request URL to a route and performs rendering if a matching route is found.
834
782
  *
835
- * @returns A Promise resolving to an array where each element is an object with string keys (representing URL parameter names)
836
- * and string values (representing the corresponding values for those parameters in the route path).
783
+ * @param request - The incoming HTTP request to be processed.
784
+ * @param matchedRoute - The metadata of the matched route for rendering.
785
+ * If not provided, the method attempts to find a matching route based on the request URL.
786
+ * @param requestContext - Optional additional context for rendering, such as request metadata.
837
787
  *
838
- * @example
839
- * ```typescript
840
- * export const serverRouteConfig: ServerRoutes[] = [
841
- * {
842
- * path: '/product/:id',
843
- * renderMode: RenderMode.Prerender,
844
- * async getPrerenderParams() {
845
- * const productService = inject(ProductService);
846
- * const ids = await productService.getIds(); // Assuming this returns ['1', '2', '3']
788
+ * @returns A promise that resolves to the rendered response, or null if no matching route is found.
789
+ */
790
+ private handleRendering;
791
+ /**
792
+ * Constructs the asset path on the server based on the provided HTTP request.
847
793
  *
848
- * return ids.map(id => ({ id })); // Generates paths like: [{ id: '1' }, { id: '2' }, { id: '3' }]
849
- * },
850
- * },
851
- * ];
852
- * ```
794
+ * This method processes the incoming request URL to derive a path corresponding
795
+ * to the requested asset. It ensures the path points to the correct file (e.g.,
796
+ * `index.html`) and removes any base href if it is not part of the asset path.
797
+ *
798
+ * @param request - The incoming HTTP request object.
799
+ * @returns The server-relative asset path derived from the request.
853
800
  */
854
- getPrerenderParams: () => Promise<Record<string, string>[]>;
855
- }
856
-
857
- /**
858
- * Configuration options for server routes.
859
- *
860
- * This interface defines the optional settings available for configuring server routes
861
- * in the server-side environment, such as specifying a path to the app shell route.
862
- *
863
- *
864
- * @see {@link provideServerRouting}
865
- * @deprecated use `provideServerRouting`. This will be removed in version 20.
866
- */
867
- export declare interface ServerRoutesConfigOptions {
801
+ private buildServerAssetPathFromRequest;
868
802
  /**
869
- * Defines the route to be used as the app shell, which serves as the main entry
870
- * point for the application. This route is often used to enable server-side rendering
871
- * of the application shell for requests that do not match any specific server route.
803
+ * Runs the registered transform hooks on the given HTML content.
804
+ *
805
+ * @param html - The raw HTML content to be transformed.
806
+ * @param url - The URL associated with the HTML content, used for context during transformations.
807
+ * @param preload - An array of URLs representing the JavaScript resources to preload.
808
+ * @returns A promise that resolves to the transformed HTML string.
872
809
  */
873
- appShellRoute?: string;
874
- }
875
-
876
- /**
877
- * A server route that uses Server-Side Rendering (SSR) mode.
878
- * @see {@link RenderMode}
879
- * @developerPreview
880
- */
881
- export declare interface ServerRouteServer extends ServerRouteCommon {
882
- /** Specifies that the route uses Server-Side Rendering (SSR) mode. */
883
- renderMode: RenderMode.Server;
884
- }
885
-
886
- /**
887
- * Helper type to represent a server routes feature.
888
- * @see {@link ServerRoutesFeatureKind}
889
- * @developerPreview
890
- */
891
- declare interface ServerRoutesFeature<FeatureKind extends ServerRoutesFeatureKind> {
892
- ɵkind: FeatureKind;
893
- ɵproviders: Provider[];
894
- }
895
-
896
- /**
897
- * Identifies a particular kind of `ServerRoutesFeatureKind`.
898
- * @see {@link ServerRoutesFeature}
899
- * @developerPreview
900
- */
901
- declare enum ServerRoutesFeatureKind {
902
- AppShell = 0
810
+ private runTransformsOnHtml;
903
811
  }
904
-
905
- /**
906
- * Configures the app shell route with the provided component.
907
- *
908
- * The app shell serves as the main entry point for the application and is commonly used
909
- * to enable server-side rendering (SSR) of the application shell. It handles requests
910
- * that do not match any specific server route, providing a fallback mechanism and improving
911
- * perceived performance during navigation.
912
- *
913
- * This configuration is particularly useful in applications leveraging Progressive Web App (PWA)
914
- * patterns, such as service workers, to deliver a seamless user experience.
915
- *
916
- * @param component The Angular component to render for the app shell route.
917
- * @returns A server routes feature configuration for the app shell.
918
- *
919
- * @see {@link provideServerRouting}
920
- * @see {@link https://angular.dev/ecosystem/service-workers/app-shell | App shell pattern on Angular.dev}
921
- */
922
- export declare function withAppShell(component: Type<unknown> | (() => Promise<Type<unknown> | DefaultExport<Type<unknown>>>)): ServerRoutesFeature<ServerRoutesFeatureKind.AppShell>;
923
-
924
- /**
925
- * Destroys the existing `AngularServerApp` instance, releasing associated resources and resetting the
926
- * reference to `undefined`.
927
- *
928
- * This function is primarily used to enable the recreation of the `AngularServerApp` instance,
929
- * typically when server configuration or application state needs to be refreshed.
930
- */
931
- export declare function ɵdestroyAngularServerApp(): void;
932
-
933
- /**
934
- * Asynchronously extracts routes from the Angular application configuration
935
- * and creates a `RouteTree` to manage server-side routing.
936
- *
937
- * @param options - An object containing the following options:
938
- * - `url`: The URL for server-side rendering. The URL is used to configure `ServerPlatformLocation`. This configuration is crucial
939
- * for ensuring that API requests for relative paths succeed, which is essential for accurate route extraction.
940
- * See:
941
- * - https://github.com/angular/angular/blob/d608b857c689d17a7ffa33bbb510301014d24a17/packages/platform-server/src/location.ts#L51
942
- * - https://github.com/angular/angular/blob/6882cc7d9eed26d3caeedca027452367ba25f2b9/packages/platform-server/src/http.ts#L44
943
- * - `manifest`: An optional `AngularAppManifest` that contains the application's routing and configuration details.
944
- * If not provided, the default manifest is retrieved using `getAngularAppManifest()`.
945
- * - `invokeGetPrerenderParams`: A boolean flag indicating whether to invoke `getPrerenderParams` for parameterized SSG routes
946
- * to handle prerendering paths. Defaults to `false`.
947
- * - `includePrerenderFallbackRoutes`: A flag indicating whether to include fallback routes in the result. Defaults to `true`.
948
- * - `signal`: An optional `AbortSignal` that can be used to abort the operation.
949
- *
950
- * @returns A promise that resolves to an object containing:
951
- * - `routeTree`: A populated `RouteTree` containing all extracted routes from the Angular application.
952
- * - `appShellRoute`: The specified route for the app-shell, if configured.
953
- * - `errors`: An array of strings representing any errors encountered during the route extraction process.
954
- */
955
- export declare function ɵextractRoutesAndCreateRouteTree(options: {
956
- url: URL;
957
- manifest?: AngularAppManifest;
958
- invokeGetPrerenderParams?: boolean;
959
- includePrerenderFallbackRoutes?: boolean;
960
- signal?: AbortSignal;
961
- }): Promise<{
962
- routeTree: RouteTree;
963
- appShellRoute?: string;
964
- errors: string[];
965
- }>;
966
-
967
812
  /**
968
813
  * Retrieves or creates an instance of `AngularServerApp`.
969
814
  * - If an instance of `AngularServerApp` already exists, it will return the existing one.
@@ -973,30 +818,44 @@ export declare function ɵextractRoutesAndCreateRouteTree(options: {
973
818
  *
974
819
  * @returns The existing or newly created instance of `AngularServerApp`.
975
820
  */
976
- export declare function ɵgetOrCreateAngularServerApp(options?: Readonly<AngularServerAppOptions>): AngularServerApp;
977
-
821
+ declare function getOrCreateAngularServerApp(options?: Readonly<AngularServerAppOptions>): AngularServerApp;
978
822
  /**
979
- * Retrieves routes from the given Angular application.
980
- *
981
- * This function initializes an Angular platform, bootstraps the application or module,
982
- * and retrieves routes from the Angular router configuration. It handles both module-based
983
- * and function-based bootstrapping. It yields the resulting routes as `RouteTreeNodeMetadata` objects or errors.
984
- *
985
- * @param bootstrap - A function that returns a promise resolving to an `ApplicationRef` or an Angular module to bootstrap.
986
- * @param document - The initial HTML document used for server-side rendering.
987
- * This document is necessary to render the application on the server.
988
- * @param url - The URL for server-side rendering. The URL is used to configure `ServerPlatformLocation`. This configuration is crucial
989
- * for ensuring that API requests for relative paths succeed, which is essential for accurate route extraction.
990
- * @param invokeGetPrerenderParams - A boolean flag indicating whether to invoke `getPrerenderParams` for parameterized SSG routes
991
- * to handle prerendering paths. Defaults to `false`.
992
- * @param includePrerenderFallbackRoutes - A flag indicating whether to include fallback routes in the result. Defaults to `true`.
993
- * @param entryPointToBrowserMapping - Maps the entry-point name to the associated JavaScript browser bundles.
823
+ * Destroys the existing `AngularServerApp` instance, releasing associated resources and resetting the
824
+ * reference to `undefined`.
994
825
  *
995
- * @returns A promise that resolves to an object of type `AngularRouterConfigResult` or errors.
826
+ * This function is primarily used to enable the recreation of the `AngularServerApp` instance,
827
+ * typically when server configuration or application state needs to be refreshed.
996
828
  */
997
- export declare function ɵgetRoutesFromAngularRouterConfig(bootstrap: AngularBootstrap, document: string, url: URL, invokeGetPrerenderParams?: boolean, includePrerenderFallbackRoutes?: boolean, entryPointToBrowserMapping?: EntryPointToBrowserMapping | undefined): Promise<AngularRouterConfigResult>;
829
+ declare function destroyAngularServerApp(): void;
998
830
 
999
- export declare class ɵInlineCriticalCssProcessor extends BeastiesBase {
831
+ /** Partial representation of an `HTMLElement`. */
832
+ interface PartialHTMLElement {
833
+ getAttribute(name: string): string | null;
834
+ setAttribute(name: string, value: string): void;
835
+ hasAttribute(name: string): boolean;
836
+ removeAttribute(name: string): void;
837
+ appendChild(child: PartialHTMLElement): void;
838
+ insertBefore(newNode: PartialHTMLElement, referenceNode?: PartialHTMLElement): void;
839
+ remove(): void;
840
+ name: string;
841
+ textContent: string;
842
+ tagName: string | null;
843
+ children: PartialHTMLElement[];
844
+ next: PartialHTMLElement | null;
845
+ prev: PartialHTMLElement | null;
846
+ }
847
+ /** Partial representation of an HTML `Document`. */
848
+ interface PartialDocument {
849
+ head: PartialHTMLElement;
850
+ createElement(tagName: string): PartialHTMLElement;
851
+ querySelector(selector: string): PartialHTMLElement | null;
852
+ }
853
+ interface BeastiesBase {
854
+ embedLinkedStylesheet(link: PartialHTMLElement, document: PartialDocument): Promise<unknown>;
855
+ }
856
+ declare class BeastiesBase extends Beasties {
857
+ }
858
+ declare class InlineCriticalCssProcessor extends BeastiesBase {
1000
859
  readFile: (path: string) => Promise<string>;
1001
860
  readonly outputPath?: string | undefined;
1002
861
  private addedCspScriptsDocuments;
@@ -1019,17 +878,132 @@ export declare class ɵInlineCriticalCssProcessor extends BeastiesBase {
1019
878
  }
1020
879
 
1021
880
  /**
1022
- * Sets the Angular app engine manifest.
881
+ * Angular server application engine.
882
+ * Manages Angular server applications (including localized ones), handles rendering requests,
883
+ * and optionally transforms index HTML before rendering.
1023
884
  *
1024
- * @param manifest - The engine manifest object to set.
885
+ * @remarks This class should be instantiated once and used as a singleton across the server-side
886
+ * application to ensure consistent handling of rendering requests and resource management.
887
+ *
888
+ * @developerPreview
1025
889
  */
1026
- export declare function ɵsetAngularAppEngineManifest(manifest: AngularAppEngineManifest): void;
890
+ declare class AngularAppEngine {
891
+ /**
892
+ * A flag to enable or disable the rendering of prerendered routes.
893
+ *
894
+ * Typically used during development to avoid prerendering all routes ahead of time,
895
+ * allowing them to be rendered on the fly as requested.
896
+ *
897
+ * @private
898
+ */
899
+ static ɵallowStaticRouteRender: boolean;
900
+ /**
901
+ * Hooks for extending or modifying the behavior of the server application.
902
+ * These hooks are used by the Angular CLI when running the development server and
903
+ * provide extensibility points for the application lifecycle.
904
+ *
905
+ * @private
906
+ */
907
+ static ɵhooks: Hooks;
908
+ /**
909
+ * The manifest for the server application.
910
+ */
911
+ private readonly manifest;
912
+ /**
913
+ * A map of supported locales from the server application's manifest.
914
+ */
915
+ private readonly supportedLocales;
916
+ /**
917
+ * A cache that holds entry points, keyed by their potential locale string.
918
+ */
919
+ private readonly entryPointsCache;
920
+ /**
921
+ * Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
922
+ * or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
923
+ *
924
+ * @param request - The HTTP request to handle.
925
+ * @param requestContext - Optional context for rendering, such as metadata associated with the request.
926
+ * @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
927
+ *
928
+ * @remarks A request to `https://www.example.com/page/index.html` will serve or render the Angular route
929
+ * corresponding to `https://www.example.com/page`.
930
+ */
931
+ handle(request: Request, requestContext?: unknown): Promise<Response | null>;
932
+ /**
933
+ * Handles requests for the base path when i18n is enabled.
934
+ * Redirects the user to a locale-specific path based on the `Accept-Language` header.
935
+ *
936
+ * @param request The incoming request.
937
+ * @returns A `Response` object with a 302 redirect, or `null` if i18n is not enabled
938
+ * or the request is not for the base path.
939
+ */
940
+ private redirectBasedOnAcceptLanguage;
941
+ /**
942
+ * Retrieves the Angular server application instance for a given request.
943
+ *
944
+ * This method checks if the request URL corresponds to an Angular application entry point.
945
+ * If so, it initializes or retrieves an instance of the Angular server application for that entry point.
946
+ * Requests that resemble file requests (except for `/index.html`) are skipped.
947
+ *
948
+ * @param request - The incoming HTTP request object.
949
+ * @returns A promise that resolves to an `AngularServerApp` instance if a valid entry point is found,
950
+ * or `null` if no entry point matches the request URL.
951
+ */
952
+ private getAngularServerAppForRequest;
953
+ /**
954
+ * Retrieves the exports for a specific entry point, caching the result.
955
+ *
956
+ * @param potentialLocale - The locale string used to find the corresponding entry point.
957
+ * @returns A promise that resolves to the entry point exports or `undefined` if not found.
958
+ */
959
+ private getEntryPointExports;
960
+ /**
961
+ * Retrieves the entry point for a given URL by determining the locale and mapping it to
962
+ * the appropriate application bundle.
963
+ *
964
+ * This method determines the appropriate entry point and locale for rendering the application by examining the URL.
965
+ * If there is only one entry point available, it is returned regardless of the URL.
966
+ * Otherwise, the method extracts a potential locale identifier from the URL and looks up the corresponding entry point.
967
+ *
968
+ * @param url - The URL of the request.
969
+ * @returns A promise that resolves to the entry point exports or `undefined` if not found.
970
+ */
971
+ private getEntryPointExportsForUrl;
972
+ }
1027
973
 
1028
974
  /**
1029
- * Sets the Angular app manifest.
975
+ * Function for handling HTTP requests in a web environment.
1030
976
  *
1031
- * @param manifest - The manifest object to set for the Angular application.
977
+ * @param request - The incoming HTTP request object.
978
+ * @returns A Promise resolving to a `Response` object, `null`, or directly a `Response`,
979
+ * supporting both synchronous and asynchronous handling.
980
+ * @developerPreview
981
+ */
982
+ type RequestHandlerFunction = (request: Request) => Promise<Response | null> | null | Response;
983
+ /**
984
+ * Annotates a request handler function with metadata, marking it as a special
985
+ * handler.
986
+ *
987
+ * @param handler - The request handler function to be annotated.
988
+ * @returns The same handler function passed in, with metadata attached.
989
+ *
990
+ * @example
991
+ * Example usage in a Hono application:
992
+ * ```ts
993
+ * const app = new Hono();
994
+ * export default createRequestHandler(app.fetch);
995
+ * ```
996
+ *
997
+ * @example
998
+ * Example usage in a H3 application:
999
+ * ```ts
1000
+ * const app = createApp();
1001
+ * const handler = toWebHandler(app);
1002
+ * export default createRequestHandler(handler);
1003
+ * ```
1004
+ * @developerPreview
1032
1005
  */
1033
- export declare function ɵsetAngularAppManifest(manifest: AngularAppManifest): void;
1006
+ declare function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction;
1034
1007
 
1035
- export { }
1008
+ export { AngularAppEngine, PrerenderFallback, RenderMode, createRequestHandler, provideServerRoutesConfig, provideServerRouting, withAppShell, InlineCriticalCssProcessor as ɵInlineCriticalCssProcessor, destroyAngularServerApp as ɵdestroyAngularServerApp, extractRoutesAndCreateRouteTree as ɵextractRoutesAndCreateRouteTree, getOrCreateAngularServerApp as ɵgetOrCreateAngularServerApp, getRoutesFromAngularRouterConfig as ɵgetRoutesFromAngularRouterConfig, setAngularAppEngineManifest as ɵsetAngularAppEngineManifest, setAngularAppManifest as ɵsetAngularAppManifest };
1009
+ export type { RequestHandlerFunction, ServerRoute, ServerRouteClient, ServerRouteCommon, ServerRoutePrerender, ServerRoutePrerenderWithParams, ServerRouteServer, ServerRoutesConfigOptions };