MCPcopy Create free account
hub / github.com/angular/angular / renderApplication

Function renderApplication

packages/platform-server/src/utils.ts:384–429  ·  view source on GitHub ↗
(
  bootstrap: (context: BootstrapContext) => Promise<ApplicationRef>,
  options: {
    document?: string | Document;
    url?: string;
    platformProviders?: Provider[];
    allowedHosts?: Readonly<string>[];
  },
)

Source from the content-addressed store, hash-verified

382 * @publicApi
383 */
384export async function renderApplication(
385 bootstrap: (context: BootstrapContext) => Promise<ApplicationRef>,
386 options: {
387 document?: string | Document;
388 url?: string;
389 platformProviders?: Provider[];
390 allowedHosts?: Readonly<string>[];
391 },
392): Promise<string> {
393 const renderAppLabel = 'renderApplication';
394 const bootstrapLabel = 'bootstrap';
395 const _renderLabel = '_render';
396 const {url, allowedHosts} = options;
397
398 validateAllowedHosts(url, allowedHosts);
399
400 startMeasuring(renderAppLabel);
401 const platformRef = createServerPlatform(options);
402 try {
403 startMeasuring(bootstrapLabel);
404 const applicationRef = await bootstrap({platformRef});
405 stopMeasuring(bootstrapLabel);
406
407 if (platformRef.destroyed || applicationRef.destroyed) {
408 return '';
409 }
410
411 startMeasuring(_renderLabel);
412
413 const measuringLabel = 'whenStable';
414 startMeasuring(measuringLabel);
415 // Block until application is stable.
416 await applicationRef.whenStable();
417 stopMeasuring(measuringLabel);
418
419 const rendered = await renderInternal(platformRef, applicationRef);
420 stopMeasuring(_renderLabel);
421 return rendered;
422 } finally {
423 try {
424 await asyncDestroyPlatform(platformRef);
425 } finally {
426 stopMeasuring(renderAppLabel);
427 }
428 }
429}
430
431function validateAllowedHosts(url: string | undefined, allowedHosts: string[] | undefined) {
432 if (typeof url === 'string') {

Callers 8

ssrFunction · 0.90
utils_spec.tsFile · 0.90
runTestFunction · 0.90
server.tsFile · 0.90
runTestFunction · 0.90
server.tsFile · 0.90
renderFunction · 0.90

Calls 8

validateAllowedHostsFunction · 0.85
startMeasuringFunction · 0.85
createServerPlatformFunction · 0.85
stopMeasuringFunction · 0.85
renderInternalFunction · 0.85
asyncDestroyPlatformFunction · 0.85
whenStableMethod · 0.65
bootstrapFunction · 0.50

Tested by

no test coverage detected