MCPcopy Index your code
hub / github.com/angular/angular-cli / handleRendering

Method handleRendering

packages/angular/ssr/src/app.ts:279–377  ·  view source on GitHub ↗

* Handles the server-side rendering process for the given HTTP request. * This method matches the request URL to a route and performs rendering if a matching route is found. * * @param request - The incoming HTTP request to be processed. * @param matchedRoute - The metadata of the matche

(
    request: Request,
    matchedRoute: RouteTreeNodeMetadata,
    requestContext?: unknown,
  )

Source from the content-addressed store, hash-verified

277 * @returns A promise that resolves to the rendered response, or null if no matching route is found.
278 */
279 private async handleRendering(
280 request: Request,
281 matchedRoute: RouteTreeNodeMetadata,
282 requestContext?: unknown,
283 ): Promise<Response | null> {
284 const { renderMode, headers, status, preload } = matchedRoute;
285
286 if (!this.allowStaticRouteRender && renderMode === RenderMode.Prerender) {
287 return null;
288 }
289
290 const url = new URL(request.url);
291 const platformProviders: StaticProvider[] = [];
292
293 const {
294 manifest: { bootstrap, locale },
295 assets,
296 } = this;
297
298 // Initialize the response with status and headers if available.
299 const responseInit = {
300 status,
301 headers: new Headers({
302 'Content-Type': 'text/html;charset=UTF-8',
303 ...(locale !== undefined ? { 'Content-Language': locale } : {}),
304 ...headers,
305 }),
306 };
307
308 if (renderMode === RenderMode.Server) {
309 // Configure platform providers for request and response only for SSR.
310 platformProviders.push(
311 {
312 provide: REQUEST,
313 useValue: request,
314 },
315 {
316 provide: REQUEST_CONTEXT,
317 useValue: requestContext,
318 },
319 {
320 provide: RESPONSE_INIT,
321 useValue: responseInit,
322 },
323 );
324 } else if (renderMode === RenderMode.Client) {
325 // Serve the client-side rendered version if the route is configured for CSR.
326 let html = await this.assets.getServerAsset('index.csr.html').text();
327 html = await this.runTransformsOnHtml(html, url, preload);
328
329 return new Response(html, responseInit);
330 }
331
332 if (locale !== undefined) {
333 platformProviders.push({
334 provide: LOCALE_ID,
335 useValue: locale,
336 });

Callers 1

handleMethod · 0.95

Calls 11

runTransformsOnHtmlMethod · 0.95
inlineCriticalCssMethod · 0.95
renderAngularFunction · 0.90
createRedirectResponseFunction · 0.90
textMethod · 0.80
getServerAssetMethod · 0.80
getIndexServerHtmlMethod · 0.80
closeMethod · 0.80
pushMethod · 0.45
contentMethod · 0.45

Tested by

no test coverage detected