@@ -53,21 +53,34 @@ 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, performing server-side rendering,
57
+ * or delivering a static file for client-side rendered routes based on the `RenderMode` setting.
57
58
*
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.
60
62
*
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
63
64
* 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.
64
78
*
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.
69
82
*/
70
- async render ( request : Request , requestContext ?: unknown ) : Promise < Response | null > {
83
+ private async getAngularServerAppForRequest ( request : Request ) : Promise < AngularServerApp | null > {
71
84
// Skip if the request looks like a file but not `/index.html`.
72
85
const url = new URL ( request . url ) ;
73
86
const entryPoint = await this . getEntryPointExportsForUrl ( url ) ;
@@ -82,26 +95,7 @@ export class AngularAppEngine {
82
95
const serverApp = getOrCreateAngularServerApp ( ) as AngularServerApp ;
83
96
serverApp . hooks = this . hooks ;
84
97
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 ;
105
99
}
106
100
107
101
/**
0 commit comments