@angular/ssr 19.0.0-rc.0 → 19.0.0-rc.2
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 +39 -47
- package/fesm2022/node.mjs.map +1 -1
- package/fesm2022/ssr.mjs +234 -155
- package/fesm2022/ssr.mjs.map +1 -1
- package/fesm2022/tokens.mjs +48 -5
- package/fesm2022/tokens.mjs.map +1 -1
- package/index.d.ts +181 -78
- package/node/index.d.ts +30 -45
- package/package.json +7 -7
- package/third_party/beasties/index.js +48 -12
- package/third_party/beasties/index.js.map +1 -1
- package/tokens/index.d.ts +38 -4
package/fesm2022/tokens.mjs
CHANGED
|
@@ -1,20 +1,63 @@
|
|
|
1
1
|
import { InjectionToken } from '@angular/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Injection token
|
|
4
|
+
* Injection token representing the current HTTP request object.
|
|
5
|
+
*
|
|
6
|
+
* Use this token to access the current request when handling server-side
|
|
7
|
+
* rendering (SSR).
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This token may be `null` in the following scenarios:
|
|
11
|
+
*
|
|
12
|
+
* * During the build processes.
|
|
13
|
+
* * When the application is rendered in the browser (client-side rendering).
|
|
14
|
+
* * When performing static site generation (SSG).
|
|
15
|
+
* * During route extraction in development (at the time of the request).
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request` on MDN}
|
|
18
|
+
*
|
|
5
19
|
* @developerPreview
|
|
6
20
|
*/
|
|
7
|
-
const REQUEST = new InjectionToken('REQUEST'
|
|
21
|
+
const REQUEST = new InjectionToken('REQUEST', {
|
|
22
|
+
providedIn: 'platform',
|
|
23
|
+
factory: () => null,
|
|
24
|
+
});
|
|
8
25
|
/**
|
|
9
|
-
* Injection token for
|
|
26
|
+
* Injection token for response initialization options.
|
|
27
|
+
*
|
|
28
|
+
* Use this token to provide response options for configuring or initializing
|
|
29
|
+
* HTTP responses in server-side rendering or API endpoints.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* This token may be `null` in the following scenarios:
|
|
33
|
+
*
|
|
34
|
+
* * During the build processes.
|
|
35
|
+
* * When the application is rendered in the browser (client-side rendering).
|
|
36
|
+
* * When performing static site generation (SSG).
|
|
37
|
+
* * During route extraction in development (at the time of the request).
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/Response | `ResponseInit` on MDN}
|
|
40
|
+
*
|
|
10
41
|
* @developerPreview
|
|
11
42
|
*/
|
|
12
|
-
const RESPONSE_INIT = new InjectionToken('RESPONSE_INIT'
|
|
43
|
+
const RESPONSE_INIT = new InjectionToken('RESPONSE_INIT', {
|
|
44
|
+
providedIn: 'platform',
|
|
45
|
+
factory: () => null,
|
|
46
|
+
});
|
|
13
47
|
/**
|
|
14
48
|
* Injection token for additional request context.
|
|
49
|
+
*
|
|
50
|
+
* Use this token to pass custom metadata or context related to the current request in server-side rendering.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* This token is only available during server-side rendering and will be `null` in other contexts.
|
|
54
|
+
*
|
|
15
55
|
* @developerPreview
|
|
16
56
|
*/
|
|
17
|
-
const REQUEST_CONTEXT = new InjectionToken('REQUEST_CONTEXT'
|
|
57
|
+
const REQUEST_CONTEXT = new InjectionToken('REQUEST_CONTEXT', {
|
|
58
|
+
providedIn: 'platform',
|
|
59
|
+
factory: () => null,
|
|
60
|
+
});
|
|
18
61
|
|
|
19
62
|
export { REQUEST, REQUEST_CONTEXT, RESPONSE_INIT };
|
|
20
63
|
//# sourceMappingURL=tokens.mjs.map
|
package/fesm2022/tokens.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.mjs","sources":["../../../../../../
|
|
1
|
+
{"version":3,"file":"tokens.mjs","sources":["../../../../../../k8-fastbuild-ST-70f2edae98f4/bin/packages/angular/ssr/tokens/src/tokens.mjs"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\nimport { InjectionToken } from '@angular/core';\n/**\n * Injection token representing the current HTTP request object.\n *\n * Use this token to access the current request when handling server-side\n * rendering (SSR).\n *\n * @remarks\n * This token may be `null` in the following scenarios:\n *\n * * During the build processes.\n * * When the application is rendered in the browser (client-side rendering).\n * * When performing static site generation (SSG).\n * * During route extraction in development (at the time of the request).\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | `Request` on MDN}\n *\n * @developerPreview\n */\nexport const REQUEST = new InjectionToken('REQUEST', {\n providedIn: 'platform',\n factory: () => null,\n});\n/**\n * Injection token for response initialization options.\n *\n * Use this token to provide response options for configuring or initializing\n * HTTP responses in server-side rendering or API endpoints.\n *\n * @remarks\n * This token may be `null` in the following scenarios:\n *\n * * During the build processes.\n * * When the application is rendered in the browser (client-side rendering).\n * * When performing static site generation (SSG).\n * * During route extraction in development (at the time of the request).\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/Response | `ResponseInit` on MDN}\n *\n * @developerPreview\n */\nexport const RESPONSE_INIT = new InjectionToken('RESPONSE_INIT', {\n providedIn: 'platform',\n factory: () => null,\n});\n/**\n * Injection token for additional request context.\n *\n * Use this token to pass custom metadata or context related to the current request in server-side rendering.\n *\n * @remarks\n * This token is only available during server-side rendering and will be `null` in other contexts.\n *\n * @developerPreview\n */\nexport const REQUEST_CONTEXT = new InjectionToken('REQUEST_CONTEXT', {\n providedIn: 'platform',\n factory: () => null,\n});\n//# sourceMappingURL=tokens.js.map"],"names":[],"mappings":";;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE;AACrD,IAAI,UAAU,EAAE,UAAU;AAC1B,IAAI,OAAO,EAAE,MAAM,IAAI;AACvB,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,aAAa,GAAG,IAAI,cAAc,CAAC,eAAe,EAAE;AACjE,IAAI,UAAU,EAAE,UAAU;AAC1B,IAAI,OAAO,EAAE,MAAM,IAAI;AACvB,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,IAAI,cAAc,CAAC,iBAAiB,EAAE;AACrE,IAAI,UAAU,EAAE,UAAU;AAC1B,IAAI,OAAO,EAAE,MAAM,IAAI;AACvB,CAAC;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -8,12 +8,21 @@ import type { Type } from '@angular/core';
|
|
|
8
8
|
* Manages Angular server applications (including localized ones), handles rendering requests,
|
|
9
9
|
* and optionally transforms index HTML before rendering.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @remarks This class should be instantiated once and used as a singleton across the server-side
|
|
12
12
|
* application to ensure consistent handling of rendering requests and resource management.
|
|
13
13
|
*
|
|
14
14
|
* @developerPreview
|
|
15
15
|
*/
|
|
16
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;
|
|
17
26
|
/**
|
|
18
27
|
* Hooks for extending or modifying the behavior of the server application.
|
|
19
28
|
* These hooks are used by the Angular CLI when running the development server and
|
|
@@ -31,30 +40,29 @@ export declare class AngularAppEngine {
|
|
|
31
40
|
*/
|
|
32
41
|
private readonly entryPointsCache;
|
|
33
42
|
/**
|
|
34
|
-
*
|
|
43
|
+
* Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
|
|
44
|
+
* or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
|
|
35
45
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
46
|
+
* @param request - The HTTP request to handle.
|
|
47
|
+
* @param requestContext - Optional context for rendering, such as metadata associated with the request.
|
|
48
|
+
* @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
|
|
38
49
|
*
|
|
39
|
-
*
|
|
40
|
-
* A request to `https://www.example.com/page/index.html` will render the Angular route
|
|
50
|
+
* @remarks A request to `https://www.example.com/page/index.html` will serve or render the Angular route
|
|
41
51
|
* corresponding to `https://www.example.com/page`.
|
|
42
|
-
*
|
|
43
|
-
* @param request - The incoming HTTP request object to be rendered.
|
|
44
|
-
* @param requestContext - Optional additional context for the request, such as metadata.
|
|
45
|
-
* @returns A promise that resolves to a Response object, or `null` if the request URL represents a file (e.g., `./logo.png`)
|
|
46
|
-
* rather than an application route.
|
|
47
52
|
*/
|
|
48
|
-
|
|
53
|
+
handle(request: Request, requestContext?: unknown): Promise<Response | null>;
|
|
49
54
|
/**
|
|
50
|
-
* Retrieves
|
|
51
|
-
*
|
|
55
|
+
* Retrieves the Angular server application instance for a given request.
|
|
56
|
+
*
|
|
57
|
+
* This method checks if the request URL corresponds to an Angular application entry point.
|
|
58
|
+
* If so, it initializes or retrieves an instance of the Angular server application for that entry point.
|
|
59
|
+
* Requests that resemble file requests (except for `/index.html`) are skipped.
|
|
52
60
|
*
|
|
53
|
-
* @param request - The incoming request object.
|
|
54
|
-
* @returns A `
|
|
55
|
-
*
|
|
61
|
+
* @param request - The incoming HTTP request object.
|
|
62
|
+
* @returns A promise that resolves to an `AngularServerApp` instance if a valid entry point is found,
|
|
63
|
+
* or `null` if no entry point matches the request URL.
|
|
56
64
|
*/
|
|
57
|
-
|
|
65
|
+
private getAngularServerAppForRequest;
|
|
58
66
|
/**
|
|
59
67
|
* Retrieves the exports for a specific entry point, caching the result.
|
|
60
68
|
*
|
|
@@ -92,15 +100,6 @@ declare interface AngularAppEngineManifest {
|
|
|
92
100
|
* This is used to determine the root path of the application.
|
|
93
101
|
*/
|
|
94
102
|
readonly basePath: string;
|
|
95
|
-
/**
|
|
96
|
-
* A map that associates static paths with their corresponding HTTP headers.
|
|
97
|
-
* Each entry in the map consists of:
|
|
98
|
-
* - `key`: The static path as a string.
|
|
99
|
-
* - `value`: An array of tuples, where each tuple contains:
|
|
100
|
-
* - `headerName`: The name of the HTTP header.
|
|
101
|
-
* - `headerValue`: The value of the HTTP header.
|
|
102
|
-
*/
|
|
103
|
-
readonly staticPathsHeaders: ReadonlyMap<string, readonly [headerName: string, headerValue: string][]>;
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
/**
|
|
@@ -113,7 +112,7 @@ declare interface AngularAppManifest {
|
|
|
113
112
|
* - `key`: The path of the asset.
|
|
114
113
|
* - `value`: A function returning a promise that resolves to the file contents of the asset.
|
|
115
114
|
*/
|
|
116
|
-
readonly assets: ReadonlyMap<string,
|
|
115
|
+
readonly assets: ReadonlyMap<string, ServerAsset>;
|
|
117
116
|
/**
|
|
118
117
|
* The bootstrap mechanism for the server application.
|
|
119
118
|
* A function that returns a promise that resolves to an `NgModule` or a function
|
|
@@ -175,6 +174,10 @@ declare interface AngularRouterConfigResult {
|
|
|
175
174
|
* A list of errors encountered during the route extraction process.
|
|
176
175
|
*/
|
|
177
176
|
errors: string[];
|
|
177
|
+
/**
|
|
178
|
+
* The specified route for the app-shell, if configured.
|
|
179
|
+
*/
|
|
180
|
+
appShellRoute?: string;
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
/**
|
|
@@ -183,11 +186,25 @@ declare interface AngularRouterConfigResult {
|
|
|
183
186
|
* The `AngularServerApp` class handles server-side rendering and asset management for a specific locale.
|
|
184
187
|
*/
|
|
185
188
|
declare class AngularServerApp {
|
|
189
|
+
private readonly options;
|
|
186
190
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
191
|
+
* Whether prerendered routes should be rendered on demand or served directly.
|
|
192
|
+
*
|
|
193
|
+
* @see {@link AngularServerAppOptions.allowStaticRouteRender} for more details.
|
|
194
|
+
*/
|
|
195
|
+
private readonly allowStaticRouteRender;
|
|
196
|
+
/**
|
|
197
|
+
* Hooks for extending or modifying server behavior.
|
|
198
|
+
*
|
|
199
|
+
* @see {@link AngularServerAppOptions.hooks} for more details.
|
|
200
|
+
*/
|
|
201
|
+
readonly hooks: Hooks;
|
|
202
|
+
/**
|
|
203
|
+
* Constructs an instance of `AngularServerApp`.
|
|
204
|
+
*
|
|
205
|
+
* @param options Optional configuration options for the server application.
|
|
189
206
|
*/
|
|
190
|
-
|
|
207
|
+
constructor(options?: Readonly<AngularServerAppOptions>);
|
|
191
208
|
/**
|
|
192
209
|
* The manifest associated with this server application.
|
|
193
210
|
*/
|
|
@@ -217,44 +234,71 @@ declare class AngularServerApp {
|
|
|
217
234
|
*/
|
|
218
235
|
private readonly criticalCssLRUCache;
|
|
219
236
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* This method processes the request and returns a response based on the specified rendering context.
|
|
237
|
+
* Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
|
|
238
|
+
* or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
|
|
223
239
|
*
|
|
224
|
-
* @param request - The
|
|
225
|
-
* @param requestContext - Optional
|
|
240
|
+
* @param request - The HTTP request to handle.
|
|
241
|
+
* @param requestContext - Optional context for rendering, such as metadata associated with the request.
|
|
242
|
+
* @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
|
|
226
243
|
*
|
|
227
|
-
* @
|
|
244
|
+
* @remarks A request to `https://www.example.com/page/index.html` will serve or render the Angular route
|
|
245
|
+
* corresponding to `https://www.example.com/page`.
|
|
228
246
|
*/
|
|
229
|
-
|
|
247
|
+
handle(request: Request, requestContext?: unknown): Promise<Response | null>;
|
|
230
248
|
/**
|
|
231
|
-
*
|
|
232
|
-
* The rendering process can be interrupted by an abort signal, where the first resolved promise (either from the abort
|
|
233
|
-
* or the render process) will dictate the outcome.
|
|
249
|
+
* Handles serving a prerendered static asset if available for the matched route.
|
|
234
250
|
*
|
|
235
|
-
*
|
|
236
|
-
* @param signal - (Optional) An `AbortSignal` object that allows for the cancellation of the rendering process.
|
|
237
|
-
* @returns A promise that resolves to the generated HTTP response object, or `null` if no matching route is found.
|
|
238
|
-
*/
|
|
239
|
-
renderStatic(url: URL, signal?: AbortSignal): Promise<Response | null>;
|
|
240
|
-
/**
|
|
241
|
-
* Creates a promise that rejects when the request is aborted.
|
|
251
|
+
* This method only supports `GET` and `HEAD` requests.
|
|
242
252
|
*
|
|
243
|
-
* @param request - The HTTP request
|
|
244
|
-
* @
|
|
253
|
+
* @param request - The incoming HTTP request for serving a static page.
|
|
254
|
+
* @param matchedRoute - The metadata of the matched route for rendering.
|
|
255
|
+
* If not provided, the method attempts to find a matching route based on the request URL.
|
|
256
|
+
* @returns A promise that resolves to a `Response` object if the prerendered page is found, or `null`.
|
|
245
257
|
*/
|
|
246
|
-
private
|
|
258
|
+
private handleServe;
|
|
247
259
|
/**
|
|
248
260
|
* Handles the server-side rendering process for the given HTTP request.
|
|
249
261
|
* This method matches the request URL to a route and performs rendering if a matching route is found.
|
|
250
262
|
*
|
|
251
263
|
* @param request - The incoming HTTP request to be processed.
|
|
252
|
-
* @param
|
|
264
|
+
* @param matchedRoute - The metadata of the matched route for rendering.
|
|
265
|
+
* If not provided, the method attempts to find a matching route based on the request URL.
|
|
253
266
|
* @param requestContext - Optional additional context for rendering, such as request metadata.
|
|
254
267
|
*
|
|
255
268
|
* @returns A promise that resolves to the rendered response, or null if no matching route is found.
|
|
256
269
|
*/
|
|
257
270
|
private handleRendering;
|
|
271
|
+
/**
|
|
272
|
+
* Returns a promise that rejects if the request is aborted.
|
|
273
|
+
*
|
|
274
|
+
* @param request - The HTTP request object being monitored for abortion.
|
|
275
|
+
* @returns A promise that never resolves and rejects with an `AbortError`
|
|
276
|
+
* if the request is aborted.
|
|
277
|
+
*/
|
|
278
|
+
private waitForRequestAbort;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Options for configuring an `AngularServerApp`.
|
|
283
|
+
*/
|
|
284
|
+
declare interface AngularServerAppOptions {
|
|
285
|
+
/**
|
|
286
|
+
* Whether to allow rendering of prerendered routes.
|
|
287
|
+
*
|
|
288
|
+
* When enabled, prerendered routes will be served directly. When disabled, they will be
|
|
289
|
+
* rendered on demand.
|
|
290
|
+
*
|
|
291
|
+
* Defaults to `false`.
|
|
292
|
+
*/
|
|
293
|
+
allowStaticRouteRender?: boolean;
|
|
294
|
+
/**
|
|
295
|
+
* Hooks for extending or modifying server behavior.
|
|
296
|
+
*
|
|
297
|
+
* This allows customization of the server's rendering process and other lifecycle events.
|
|
298
|
+
*
|
|
299
|
+
* If not provided, a new `Hooks` instance is created.
|
|
300
|
+
*/
|
|
301
|
+
hooks?: Hooks;
|
|
258
302
|
}
|
|
259
303
|
|
|
260
304
|
declare interface BeastiesBase {
|
|
@@ -296,7 +340,7 @@ declare interface EntryPointExports {
|
|
|
296
340
|
/**
|
|
297
341
|
* A reference to the function that creates an Angular server application instance.
|
|
298
342
|
*
|
|
299
|
-
* @
|
|
343
|
+
* @remarks The return type is `unknown` to prevent circular dependency issues.
|
|
300
344
|
*/
|
|
301
345
|
ɵgetOrCreateAngularServerApp: () => unknown;
|
|
302
346
|
/**
|
|
@@ -397,7 +441,7 @@ declare interface PartialHTMLElement {
|
|
|
397
441
|
/**
|
|
398
442
|
* Defines the fallback strategies for Static Site Generation (SSG) routes when a pre-rendered path is not available.
|
|
399
443
|
* This is particularly relevant for routes with parameterized URLs where some paths might not be pre-rendered at build time.
|
|
400
|
-
*
|
|
444
|
+
* @see {@link ServerRoutePrerenderWithParams}
|
|
401
445
|
* @developerPreview
|
|
402
446
|
*/
|
|
403
447
|
export declare enum PrerenderFallback {
|
|
@@ -419,27 +463,37 @@ export declare enum PrerenderFallback {
|
|
|
419
463
|
}
|
|
420
464
|
|
|
421
465
|
/**
|
|
422
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Sets up the necessary providers for configuring server routes.
|
|
468
|
+
* This function accepts an array of server routes and optional configuration
|
|
469
|
+
* options, returning an `EnvironmentProviders` object that encapsulates
|
|
470
|
+
* the server routes and configuration settings.
|
|
423
471
|
*
|
|
424
472
|
* @param routes - An array of server routes to be provided.
|
|
473
|
+
* @param options - (Optional) An object containing additional configuration options for server routes.
|
|
474
|
+
* @returns An `EnvironmentProviders` instance with the server routes configuration.
|
|
475
|
+
*
|
|
425
476
|
* @returns An `EnvironmentProviders` object that contains the server routes configuration.
|
|
477
|
+
*
|
|
478
|
+
* @see {@link ServerRoute}
|
|
479
|
+
* @see {@link ServerRoutesConfigOptions}
|
|
426
480
|
* @developerPreview
|
|
427
481
|
*/
|
|
428
|
-
export declare function provideServerRoutesConfig(routes: ServerRoute[]): EnvironmentProviders;
|
|
482
|
+
export declare function provideServerRoutesConfig(routes: ServerRoute[], options?: ServerRoutesConfigOptions): EnvironmentProviders;
|
|
429
483
|
|
|
430
484
|
/**
|
|
431
485
|
* Different rendering modes for server routes.
|
|
486
|
+
* @see {@link provideServerRoutesConfig}
|
|
487
|
+
* @see {@link ServerRoute}
|
|
432
488
|
* @developerPreview
|
|
433
489
|
*/
|
|
434
490
|
export declare enum RenderMode {
|
|
435
|
-
/** AppShell rendering mode, typically used for pre-rendered shells of the application. */
|
|
436
|
-
AppShell = 0,
|
|
437
491
|
/** Server-Side Rendering (SSR) mode, where content is rendered on the server for each request. */
|
|
438
|
-
Server =
|
|
492
|
+
Server = 0,
|
|
439
493
|
/** Client-Side Rendering (CSR) mode, where content is rendered on the client side in the browser. */
|
|
440
|
-
Client =
|
|
494
|
+
Client = 1,
|
|
441
495
|
/** Static Site Generation (SSG) mode, where content is pre-rendered at build time and served as static files. */
|
|
442
|
-
Prerender =
|
|
496
|
+
Prerender = 2
|
|
443
497
|
}
|
|
444
498
|
|
|
445
499
|
|
|
@@ -449,8 +503,9 @@ export declare enum RenderMode {
|
|
|
449
503
|
* @param request - The incoming HTTP request object.
|
|
450
504
|
* @returns A Promise resolving to a `Response` object, `null`, or directly a `Response`,
|
|
451
505
|
* supporting both synchronous and asynchronous handling.
|
|
506
|
+
* @developerPreview
|
|
452
507
|
*/
|
|
453
|
-
declare type RequestHandlerFunction = (request: Request) => Promise<Response | null> | null | Response;
|
|
508
|
+
export declare type RequestHandlerFunction = (request: Request) => Promise<Response | null> | null | Response;
|
|
454
509
|
|
|
455
510
|
/**
|
|
456
511
|
* A route tree implementation that supports efficient route matching, including support for wildcard routes.
|
|
@@ -623,9 +678,8 @@ declare interface RouteTreeNodeMetadata {
|
|
|
623
678
|
headers?: Record<string, string>;
|
|
624
679
|
/**
|
|
625
680
|
* Specifies the rendering mode used for this route.
|
|
626
|
-
* If not provided, the default rendering mode for the application will be used.
|
|
627
681
|
*/
|
|
628
|
-
renderMode
|
|
682
|
+
renderMode: RenderMode;
|
|
629
683
|
}
|
|
630
684
|
|
|
631
685
|
/**
|
|
@@ -640,31 +694,47 @@ declare type RouteTreeNodeMetadataWithoutRoute = Omit<RouteTreeNodeMetadata, 'ro
|
|
|
640
694
|
declare type SerializableRouteTreeNode = ReadonlyArray<RouteTreeNodeMetadata>;
|
|
641
695
|
|
|
642
696
|
/**
|
|
643
|
-
*
|
|
644
|
-
* @developerPreview
|
|
697
|
+
* Represents of a server asset stored in the manifest.
|
|
645
698
|
*/
|
|
646
|
-
|
|
699
|
+
declare interface ServerAsset {
|
|
700
|
+
/**
|
|
701
|
+
* Retrieves the text content of the asset.
|
|
702
|
+
*
|
|
703
|
+
* @returns A promise that resolves to the asset's content as a string.
|
|
704
|
+
*/
|
|
705
|
+
text: () => Promise<string>;
|
|
706
|
+
/**
|
|
707
|
+
* A hash string representing the asset's content.
|
|
708
|
+
*/
|
|
709
|
+
hash: string;
|
|
710
|
+
/**
|
|
711
|
+
* The size of the asset's content in bytes.
|
|
712
|
+
*/
|
|
713
|
+
size: number;
|
|
714
|
+
}
|
|
647
715
|
|
|
648
716
|
/**
|
|
649
|
-
*
|
|
717
|
+
* Server route configuration.
|
|
718
|
+
* @see {@link provideServerRoutesConfig}
|
|
719
|
+
* @developerPreview
|
|
650
720
|
*/
|
|
651
|
-
declare
|
|
652
|
-
/** Specifies that the route uses AppShell rendering mode. */
|
|
653
|
-
renderMode: RenderMode.AppShell;
|
|
654
|
-
}
|
|
721
|
+
export declare type ServerRoute = ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer;
|
|
655
722
|
|
|
656
723
|
/**
|
|
657
724
|
* A server route that uses Client-Side Rendering (CSR) mode.
|
|
725
|
+
* @see {@link RenderMode}
|
|
726
|
+
* @developerPreview
|
|
658
727
|
*/
|
|
659
|
-
declare interface ServerRouteClient extends ServerRouteCommon {
|
|
728
|
+
export declare interface ServerRouteClient extends ServerRouteCommon {
|
|
660
729
|
/** Specifies that the route uses Client-Side Rendering (CSR) mode. */
|
|
661
730
|
renderMode: RenderMode.Client;
|
|
662
731
|
}
|
|
663
732
|
|
|
664
733
|
/**
|
|
665
734
|
* Common interface for server routes, providing shared properties.
|
|
735
|
+
* @developerPreview
|
|
666
736
|
*/
|
|
667
|
-
declare interface ServerRouteCommon {
|
|
737
|
+
export declare interface ServerRouteCommon {
|
|
668
738
|
/** The path associated with this route. */
|
|
669
739
|
path: string;
|
|
670
740
|
/** Optional additional headers to include in the response for this route. */
|
|
@@ -675,8 +745,10 @@ declare interface ServerRouteCommon {
|
|
|
675
745
|
|
|
676
746
|
/**
|
|
677
747
|
* A server route that uses Static Site Generation (SSG) mode.
|
|
748
|
+
* @see {@link RenderMode}
|
|
749
|
+
* @developerPreview
|
|
678
750
|
*/
|
|
679
|
-
declare interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'> {
|
|
751
|
+
export declare interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'> {
|
|
680
752
|
/** Specifies that the route uses Static Site Generation (SSG) mode. */
|
|
681
753
|
renderMode: RenderMode.Prerender;
|
|
682
754
|
/** Fallback cannot be specified unless `getPrerenderParams` is used. */
|
|
@@ -685,8 +757,12 @@ declare interface ServerRoutePrerender extends Omit<ServerRouteCommon, 'status'>
|
|
|
685
757
|
|
|
686
758
|
/**
|
|
687
759
|
* A server route configuration that uses Static Site Generation (SSG) mode, including support for routes with parameters.
|
|
760
|
+
* @see {@link RenderMode}
|
|
761
|
+
* @see {@link ServerRoutePrerender}
|
|
762
|
+
* @see {@link PrerenderFallback}
|
|
763
|
+
* @developerPreview
|
|
688
764
|
*/
|
|
689
|
-
declare interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerender, 'fallback'> {
|
|
765
|
+
export declare interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerender, 'fallback'> {
|
|
690
766
|
/**
|
|
691
767
|
* Optional strategy to use if the SSG path is not pre-rendered.
|
|
692
768
|
* This is especially relevant for routes with parameterized URLs, where some paths may not be pre-rendered at build time.
|
|
@@ -725,10 +801,32 @@ declare interface ServerRoutePrerenderWithParams extends Omit<ServerRoutePrerend
|
|
|
725
801
|
getPrerenderParams: () => Promise<Record<string, string>[]>;
|
|
726
802
|
}
|
|
727
803
|
|
|
804
|
+
/**
|
|
805
|
+
* Configuration options for server routes.
|
|
806
|
+
*
|
|
807
|
+
* This interface defines the optional settings available for configuring server routes
|
|
808
|
+
* in the server-side environment, such as specifying a path to the app shell route.
|
|
809
|
+
*
|
|
810
|
+
* @see {@link provideServerRoutesConfig}
|
|
811
|
+
* @developerPreview
|
|
812
|
+
*/
|
|
813
|
+
export declare interface ServerRoutesConfigOptions {
|
|
814
|
+
/**
|
|
815
|
+
* Defines the route to be used as the app shell, which serves as the main entry
|
|
816
|
+
* point for the application. This route is often used to enable server-side rendering
|
|
817
|
+
* of the application shell for requests that do not match any specific server route.
|
|
818
|
+
*
|
|
819
|
+
* @see {@link https://angular.dev/ecosystem/service-workers/app-shell | App shell pattern on Angular.dev}
|
|
820
|
+
*/
|
|
821
|
+
appShellRoute?: string;
|
|
822
|
+
}
|
|
823
|
+
|
|
728
824
|
/**
|
|
729
825
|
* A server route that uses Server-Side Rendering (SSR) mode.
|
|
826
|
+
* @see {@link RenderMode}
|
|
827
|
+
* @developerPreview
|
|
730
828
|
*/
|
|
731
|
-
declare interface ServerRouteServer extends ServerRouteCommon {
|
|
829
|
+
export declare interface ServerRouteServer extends ServerRouteCommon {
|
|
732
830
|
/** Specifies that the route uses Server-Side Rendering (SSR) mode. */
|
|
733
831
|
renderMode: RenderMode.Server;
|
|
734
832
|
}
|
|
@@ -759,10 +857,12 @@ export declare function ɵdestroyAngularServerApp(): void;
|
|
|
759
857
|
*
|
|
760
858
|
* @returns A promise that resolves to an object containing:
|
|
761
859
|
* - `routeTree`: A populated `RouteTree` containing all extracted routes from the Angular application.
|
|
860
|
+
* - `appShellRoute`: The specified route for the app-shell, if configured.
|
|
762
861
|
* - `errors`: An array of strings representing any errors encountered during the route extraction process.
|
|
763
862
|
*/
|
|
764
863
|
export declare function ɵextractRoutesAndCreateRouteTree(url: URL, manifest?: AngularAppManifest, invokeGetPrerenderParams?: boolean, includePrerenderFallbackRoutes?: boolean): Promise<{
|
|
765
864
|
routeTree: RouteTree;
|
|
865
|
+
appShellRoute?: string;
|
|
766
866
|
errors: string[];
|
|
767
867
|
}>;
|
|
768
868
|
|
|
@@ -770,9 +870,12 @@ export declare function ɵextractRoutesAndCreateRouteTree(url: URL, manifest?: A
|
|
|
770
870
|
* Retrieves or creates an instance of `AngularServerApp`.
|
|
771
871
|
* - If an instance of `AngularServerApp` already exists, it will return the existing one.
|
|
772
872
|
* - If no instance exists, it will create a new one with the provided options.
|
|
873
|
+
*
|
|
874
|
+
* @param options Optional configuration options for the server application.
|
|
875
|
+
*
|
|
773
876
|
* @returns The existing or newly created instance of `AngularServerApp`.
|
|
774
877
|
*/
|
|
775
|
-
export declare function ɵgetOrCreateAngularServerApp(): AngularServerApp;
|
|
878
|
+
export declare function ɵgetOrCreateAngularServerApp(options?: Readonly<AngularServerAppOptions>): AngularServerApp;
|
|
776
879
|
|
|
777
880
|
/**
|
|
778
881
|
* Retrieves routes from the given Angular application.
|
package/node/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ApplicationRef } from '@angular/core';
|
|
2
|
+
import type { Http2ServerRequest } from 'node:http2';
|
|
3
|
+
import type { Http2ServerResponse } from 'node:http2';
|
|
2
4
|
import type { IncomingMessage } from 'node:http';
|
|
3
5
|
import type { ServerResponse } from 'node:http';
|
|
4
6
|
import { StaticProvider } from '@angular/core';
|
|
@@ -9,7 +11,7 @@ import { Type } from '@angular/core';
|
|
|
9
11
|
* Manages Angular server applications (including localized ones), handles rendering requests,
|
|
10
12
|
* and optionally transforms index HTML before rendering.
|
|
11
13
|
*
|
|
12
|
-
* @
|
|
14
|
+
* @remarks This class should be instantiated once and used as a singleton across the server-side
|
|
13
15
|
* application to ensure consistent handling of rendering requests and resource management.
|
|
14
16
|
*
|
|
15
17
|
* @developerPreview
|
|
@@ -17,46 +19,20 @@ import { Type } from '@angular/core';
|
|
|
17
19
|
export declare class AngularNodeAppEngine {
|
|
18
20
|
private readonly angularAppEngine;
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
|
|
23
|
+
* or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
|
|
21
24
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* the method returns `null`.
|
|
25
|
+
* This method adapts Node.js's `IncomingMessage` or `Http2ServerRequest`
|
|
26
|
+
* to a format compatible with the `AngularAppEngine` and delegates the handling logic to it.
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
* associated with
|
|
28
|
+
* @param request - The incoming HTTP request (`IncomingMessage` or `Http2ServerRequest`).
|
|
29
|
+
* @param requestContext - Optional context for rendering, such as metadata associated with the request.
|
|
30
|
+
* @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
|
|
28
31
|
*
|
|
29
|
-
* @
|
|
30
|
-
*
|
|
31
|
-
* @returns A promise that resolves to a `Response` object, or `null` if the request URL is for a static file
|
|
32
|
-
* (e.g., `./logo.png`) rather than an application route.
|
|
32
|
+
* @remarks A request to `https://www.example.com/page/index.html` will serve or render the Angular route
|
|
33
|
+
* corresponding to `https://www.example.com/page`.
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves HTTP headers for a request associated with statically generated (SSG) pages,
|
|
37
|
-
* based on the URL pathname.
|
|
38
|
-
*
|
|
39
|
-
* @param request - The incoming request object.
|
|
40
|
-
* @returns A `Map` containing the HTTP headers as key-value pairs.
|
|
41
|
-
* @note This function should be used exclusively for retrieving headers of SSG pages.
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const angularAppEngine = new AngularNodeAppEngine();
|
|
45
|
-
*
|
|
46
|
-
* app.use(express.static('dist/browser', {
|
|
47
|
-
* setHeaders: (res, path) => {
|
|
48
|
-
* // Retrieve headers for the current request
|
|
49
|
-
* const headers = angularAppEngine.getPrerenderHeaders(res.req);
|
|
50
|
-
*
|
|
51
|
-
* // Apply the retrieved headers to the response
|
|
52
|
-
* for (const [key, value] of headers) {
|
|
53
|
-
* res.setHeader(key, value);
|
|
54
|
-
* }
|
|
55
|
-
* }
|
|
56
|
-
}));
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
getPrerenderHeaders(request: IncomingMessage): ReadonlyMap<string, string>;
|
|
35
|
+
handle(request: IncomingMessage | Http2ServerRequest, requestContext?: unknown): Promise<Response | null>;
|
|
60
36
|
}
|
|
61
37
|
|
|
62
38
|
/**
|
|
@@ -153,16 +129,20 @@ export declare interface CommonEngineRenderOptions {
|
|
|
153
129
|
* ```
|
|
154
130
|
* @developerPreview
|
|
155
131
|
*/
|
|
156
|
-
export declare function createNodeRequestHandler<T extends
|
|
132
|
+
export declare function createNodeRequestHandler<T extends NodeRequestHandlerFunction>(handler: T): T;
|
|
157
133
|
|
|
158
134
|
/**
|
|
159
|
-
* Converts a Node.js `IncomingMessage` into a
|
|
135
|
+
* Converts a Node.js `IncomingMessage` or `Http2ServerRequest` into a
|
|
136
|
+
* Web Standard `Request` object.
|
|
137
|
+
*
|
|
138
|
+
* This function adapts the Node.js request objects to a format that can
|
|
139
|
+
* be used by web platform APIs.
|
|
160
140
|
*
|
|
161
|
-
* @param nodeRequest - The Node.js `IncomingMessage`
|
|
141
|
+
* @param nodeRequest - The Node.js request object (`IncomingMessage` or `Http2ServerRequest`) to convert.
|
|
162
142
|
* @returns A Web Standard `Request` object.
|
|
163
143
|
* @developerPreview
|
|
164
144
|
*/
|
|
165
|
-
export declare function createWebRequestFromNodeRequest(nodeRequest: IncomingMessage): Request;
|
|
145
|
+
export declare function createWebRequestFromNodeRequest(nodeRequest: IncomingMessage | Http2ServerRequest): Request;
|
|
166
146
|
|
|
167
147
|
|
|
168
148
|
/**
|
|
@@ -191,17 +171,22 @@ export declare function isMainModule(url: string): boolean;
|
|
|
191
171
|
* @param next - A callback function that signals the completion of the middleware or forwards the error if provided.
|
|
192
172
|
*
|
|
193
173
|
* @returns A Promise that resolves to void or simply void. The handler can be asynchronous.
|
|
174
|
+
* @developerPreview
|
|
194
175
|
*/
|
|
195
|
-
declare type
|
|
176
|
+
export declare type NodeRequestHandlerFunction = (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => Promise<void> | void;
|
|
196
177
|
|
|
197
178
|
/**
|
|
198
|
-
* Streams a web-standard `Response` into a Node.js `ServerResponse
|
|
179
|
+
* Streams a web-standard `Response` into a Node.js `ServerResponse`
|
|
180
|
+
* or `Http2ServerResponse`.
|
|
181
|
+
*
|
|
182
|
+
* This function adapts the web `Response` object to write its content
|
|
183
|
+
* to a Node.js response object, handling both HTTP/1.1 and HTTP/2.
|
|
199
184
|
*
|
|
200
185
|
* @param source - The web-standard `Response` object to stream from.
|
|
201
|
-
* @param destination - The Node.js `ServerResponse`
|
|
186
|
+
* @param destination - The Node.js response object (`ServerResponse` or `Http2ServerResponse`) to stream into.
|
|
202
187
|
* @returns A promise that resolves once the streaming operation is complete.
|
|
203
188
|
* @developerPreview
|
|
204
189
|
*/
|
|
205
|
-
export declare function writeResponseToNodeResponse(source: Response, destination: ServerResponse): Promise<void>;
|
|
190
|
+
export declare function writeResponseToNodeResponse(source: Response, destination: ServerResponse | Http2ServerResponse<Http2ServerRequest>): Promise<void>;
|
|
206
191
|
|
|
207
192
|
export { }
|