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