@@ -53,21 +53,34 @@ export class AngularAppEngine {
5353 private readonly entryPointsCache = new Map < string , Promise < EntryPointExports > > ( ) ;
5454
5555 /**
56- * Renders a response for the given HTTP request using the server application.
56+ * Handles an incoming HTTP request by serving prerendered content, performing server-side rendering,
57+ * or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
5758 *
58- * This method processes the request, determines the appropriate route and rendering context,
59- * and returns an HTTP response.
59+ * @param request - The HTTP request to handle.
60+ * @param requestContext - Optional context for rendering, such as metadata associated with the request.
61+ * @returns A promise that resolves to the resulting HTTP response object, or `null` if no matching Angular route is found.
6062 *
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+ * @note A request to `https://www.example.com/page/index.html` will serve or render the Angular route
6364 * corresponding to `https://www.example.com/page`.
65+ */
66+ async handle ( request : Request , requestContext ?: unknown ) : Promise < Response | null > {
67+ const serverApp = await this . getAngularServerAppForRequest ( request ) ;
68+
69+ return serverApp ? serverApp . handle ( request , requestContext ) : null ;
70+ }
71+
72+ /**
73+ * Retrieves the Angular server application instance for a given request.
74+ *
75+ * This method checks if the request URL corresponds to an Angular application entry point.
76+ * If so, it initializes or retrieves an instance of the Angular server application for that entry point.
77+ * Requests that resemble file requests (except for `/index.html`) are skipped.
6478 *
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.
79+ * @param request - The incoming HTTP request object.
80+ * @returns A promise that resolves to an `AngularServerApp` instance if a valid entry point is found,
81+ * or `null` if no entry point matches the request URL.
6982 */
70- async render ( request : Request , requestContext ?: unknown ) : Promise < Response | null > {
83+ private async getAngularServerAppForRequest ( request : Request ) : Promise < AngularServerApp | null > {
7184 // Skip if the request looks like a file but not `/index.html`.
7285 const url = new URL ( request . url ) ;
7386 const entryPoint = await this . getEntryPointExportsForUrl ( url ) ;
@@ -82,26 +95,7 @@ export class AngularAppEngine {
8295 const serverApp = getOrCreateAngularServerApp ( ) as AngularServerApp ;
8396 serverApp . hooks = this . hooks ;
8497
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 ) ;
98+ return serverApp ;
10599 }
106100
107101 /**
0 commit comments