@@ -53,21 +53,37 @@ export class AngularAppEngine {
53
53
private readonly entryPointsCache = new Map < string , Promise < EntryPointExports > > ( ) ;
54
54
55
55
/**
56
- * Renders a response for the given HTTP request using the server application .
56
+ * Handles an incoming HTTP request by serving prerendered content or performing server-side rendering .
57
57
*
58
- * This method processes the request, determines the appropriate route and rendering context,
59
- * and returns an HTTP response.
58
+ * This method prioritizes serving a prerendered version of the requested page. If no prerendered content is available,
59
+ * it falls back on server-side rendering to dynamically generate the page. The function returns a promise that resolves
60
+ * to the appropriate HTTP response.
60
61
*
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
62
+ * @param request - The HTTP request to handle.
63
+ * @param requestContext - Optional context for rendering, such as metadata associated with the request.
64
+ * @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
65
+ *
66
+ * @note A request to `https://www.example.com/page/index.html` will serve or render the Angular route
63
67
* corresponding to `https://www.example.com/page`.
68
+ */
69
+ async handle ( request : Request , requestContext ?: unknown ) : Promise < Response | null > {
70
+ const serverApp = await this . getAngularServerAppForRequest ( request ) ;
71
+
72
+ return serverApp ? serverApp . handle ( request , requestContext ) : null ;
73
+ }
74
+
75
+ /**
76
+ * Retrieves the Angular server application instance for a given request.
64
77
*
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.
78
+ * This method checks if the request URL corresponds to an Angular application entry point.
79
+ * If so, it initializes or retrieves an instance of the Angular server application for that entry point.
80
+ * Requests that resemble file requests (except for `/index.html`) are skipped.
81
+ *
82
+ * @param request - The incoming HTTP request object.
83
+ * @returns A promise that resolves to an `AngularServerApp` instance if a valid entry point is found,
84
+ * or `null` if no entry point matches the request URL.
69
85
*/
70
- async render ( request : Request , requestContext ?: unknown ) : Promise < Response | null > {
86
+ private async getAngularServerAppForRequest ( request : Request ) : Promise < AngularServerApp | null > {
71
87
// Skip if the request looks like a file but not `/index.html`.
72
88
const url = new URL ( request . url ) ;
73
89
const entryPoint = await this . getEntryPointExportsForUrl ( url ) ;
@@ -82,26 +98,7 @@ export class AngularAppEngine {
82
98
const serverApp = getOrCreateAngularServerApp ( ) as AngularServerApp ;
83
99
serverApp . hooks = this . hooks ;
84
100
85
- return serverApp . render ( request , requestContext ) ;
86
- }
87
-
88
- /**
89
- * Retrieves HTTP headers for a request associated with statically generated (SSG) pages,
90
- * based on the URL pathname.
91
- *
92
- * @param request - The incoming request object.
93
- * @returns A `Map` containing the HTTP headers as key-value pairs.
94
- * @note This function should be used exclusively for retrieving headers of SSG pages.
95
- */
96
- getPrerenderHeaders ( request : Request ) : ReadonlyMap < string , string > {
97
- if ( this . manifest . staticPathsHeaders . size === 0 ) {
98
- return new Map ( ) ;
99
- }
100
-
101
- const { pathname } = stripIndexHtmlFromURL ( new URL ( request . url ) ) ;
102
- const headers = this . manifest . staticPathsHeaders . get ( stripTrailingSlash ( pathname ) ) ;
103
-
104
- return new Map ( headers ) ;
101
+ return serverApp ;
105
102
}
106
103
107
104
/**
0 commit comments