Skip to content

Commit a9ab5e7

Browse files
committed
fixup! fix(@angular/ssr): enable serving of prerendered pages in the App Engine
1 parent 1f60d7c commit a9ab5e7

File tree

12 files changed

+212
-255
lines changed

12 files changed

+212
-255
lines changed

goldens/public-api/angular/ssr/index.api.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { EnvironmentProviders } from '@angular/core';
88

99
// @public
1010
export class AngularAppEngine {
11-
process(request: Request, requestContext?: unknown): Promise<Response | null>;
12-
render(request: Request, requestContext?: unknown): Promise<Response | null>;
13-
serve(request: Request): Promise<Response | null>;
11+
handle(request: Request, requestContext?: unknown): Promise<Response | null>;
1412
static ɵhooks: Hooks;
1513
}
1614

goldens/public-api/angular/ssr/node/index.api.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import { Type } from '@angular/core';
1212

1313
// @public
1414
export class AngularNodeAppEngine {
15-
process(request: IncomingMessage, requestContext?: unknown): Promise<Response | null>;
16-
render(request: IncomingMessage, requestContext?: unknown): Promise<Response | null>;
17-
serve(request: IncomingMessage): Promise<Response | null>;
15+
handle(request: IncomingMessage, requestContext?: unknown): Promise<Response | null>;
1816
}
1917

2018
// @public

packages/angular/build/src/builders/application/execute-post-bundle.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export async function executePostBundleSteps(
183183
}
184184
case RouteRenderMode.Server:
185185
case RouteRenderMode.Client:
186-
case RouteRenderMode.AppShell:
187186
serializableRouteTreeNodeForManifest.push(metadata);
188187

189188
break;

packages/angular/build/src/utils/server-rendering/manifest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import { extname } from 'node:path';
910
import {
10-
INDEX_HTML_CSR,
11-
INDEX_HTML_SERVER,
1211
NormalizedApplicationBuildOptions,
1312
getLocaleBaseHref,
1413
} from '../../builders/application/options';
@@ -135,7 +134,8 @@ export function generateAngularServerAppManifest(
135134
): string {
136135
const serverAssetsContent: string[] = [];
137136
for (const file of [...additionalHtmlOutputFiles.values(), ...outputFiles]) {
138-
if (file.path.endsWith('.html') || (inlineCriticalCss && file.path.endsWith('.css'))) {
137+
const extension = extname(file.path);
138+
if (extension === '.html' || (inlineCriticalCss && extension === '.css')) {
139139
serverAssetsContent.push(`['${file.path}', async () => \`${escapeUnsafeChars(file.text)}\`]`);
140140
}
141141
}

packages/angular/ssr/node/src/app-engine.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,6 @@ import { createWebRequestFromNodeRequest } from './request';
2323
export class AngularNodeAppEngine {
2424
private readonly angularAppEngine = new AngularAppEngine();
2525

26-
/**
27-
* Renders an HTTP response based on the incoming request using the Angular server application.
28-
*
29-
* The method processes the incoming request, determines the appropriate route, and prepares the
30-
* rendering context to generate a response. If the request URL corresponds to a static file (excluding `/index.html`),
31-
* the method returns `null`.
32-
*
33-
* Example: A request to `https://www.example.com/page/index.html` will render the Angular route
34-
* associated with `https://www.example.com/page`.
35-
*
36-
* @param request - The incoming HTTP request object to be rendered.
37-
* @param requestContext - Optional additional context for the request, such as metadata or custom settings.
38-
* @returns A promise that resolves to a `Response` object, or `null` if the request URL is for a static file
39-
* (e.g., `./logo.png`) rather than an application route.
40-
*/
41-
render(request: IncomingMessage, requestContext?: unknown): Promise<Response | null> {
42-
return this.angularAppEngine.render(createWebRequestFromNodeRequest(request), requestContext);
43-
}
44-
45-
/**
46-
* Serves a prerendered page for a given request.
47-
*
48-
* This method examines the incoming request to determine if it corresponds to a known prerendered page.
49-
* If a matching page is found, it returns a `Response` object containing the page content; otherwise, it returns `null`.
50-
*
51-
* @param request - The incoming HTTP request for a prerendered page.
52-
* @returns A promise that resolves to a `Response` object containing the prerendered page content, or `null`
53-
* if no matching page is found.
54-
*/
55-
serve(request: IncomingMessage): Promise<Response | null> {
56-
return this.angularAppEngine.serve(createWebRequestFromNodeRequest(request));
57-
}
58-
5926
/**
6027
* Handles incoming HTTP requests by serving prerendered content or rendering the page.
6128
*
@@ -68,12 +35,9 @@ export class AngularNodeAppEngine {
6835
* @returns A promise that resolves to the HTTP response object resulting from the request handling,
6936
* or null if no matching content is found.
7037
*/
71-
async process(request: IncomingMessage, requestContext?: unknown): Promise<Response | null> {
38+
async handle(request: IncomingMessage, requestContext?: unknown): Promise<Response | null> {
7239
const webRequest = createWebRequestFromNodeRequest(request);
7340

74-
return (
75-
(await this.angularAppEngine.serve(webRequest)) ??
76-
(await this.angularAppEngine.render(webRequest, requestContext))
77-
);
41+
return this.angularAppEngine.handle(webRequest, requestContext);
7842
}
7943
}

packages/angular/ssr/src/app-engine.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,43 +52,6 @@ export class AngularAppEngine {
5252
*/
5353
private readonly entryPointsCache = new Map<string, Promise<EntryPointExports>>();
5454

55-
/**
56-
* Renders a response for the given HTTP request using the server application.
57-
*
58-
* This method processes the request, determines the appropriate route and rendering context,
59-
* and returns an HTTP response.
60-
*
61-
* If the request URL appears to be for a file (excluding `/index.html`), the method returns `null`.
62-
* A request to `https://www.example.com/page/index.html` will render the Angular route
63-
* corresponding to `https://www.example.com/page`.
64-
*
65-
* @param request - The incoming HTTP request object to be rendered.
66-
* @param requestContext - Optional additional context for the request, such as metadata.
67-
* @returns A promise that resolves to a Response object, or `null` if the request URL represents a file (e.g., `./logo.png`)
68-
* rather than an application route.
69-
*/
70-
async render(request: Request, requestContext?: unknown): Promise<Response | null> {
71-
const serverApp = await this.getAngularServerAppForRequest(request);
72-
73-
return serverApp ? serverApp.render(request, requestContext) : null;
74-
}
75-
76-
/**
77-
* Serves a prerendered page for a given request.
78-
*
79-
* This method examines the incoming request to determine if it corresponds to a known prerendered page.
80-
* If a matching page is found, it returns a `Response` object containing the page content; otherwise, it returns `null`.
81-
*
82-
* @param request - The incoming HTTP request object to be rendered.
83-
* @returns A promise that resolves to a `Response` object containing the prerendered page content, or `null`
84-
* if no matching page is found.
85-
**/
86-
async serve(request: Request): Promise<Response | null> {
87-
const serverApp = await this.getAngularServerAppForRequest(request);
88-
89-
return serverApp ? serverApp.serve(request) : null;
90-
}
91-
9255
/**
9356
* Handles incoming HTTP requests by serving prerendered content or rendering the page.
9457
*
@@ -101,13 +64,10 @@ export class AngularAppEngine {
10164
* @returns A promise that resolves to the HTTP response object resulting from the request handling,
10265
* or null if no matching content is found.
10366
*/
104-
async process(request: Request, requestContext?: unknown): Promise<Response | null> {
67+
async handle(request: Request, requestContext?: unknown): Promise<Response | null> {
10568
const serverApp = await this.getAngularServerAppForRequest(request);
106-
if (!serverApp) {
107-
return null;
108-
}
10969

110-
return (await serverApp.serve(request)) ?? (await serverApp.render(request, requestContext));
70+
return serverApp ? serverApp.handle(request, requestContext) : null;
11171
}
11272

11373
/**

0 commit comments

Comments
 (0)