(
bootstrap: (context: BootstrapContext) => Promise<ApplicationRef>,
options: {
document?: string | Document;
url?: string;
platformProviders?: Provider[];
allowedHosts?: Readonly<string>[];
},
)
| 382 | * @publicApi |
| 383 | */ |
| 384 | export 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 | |
| 431 | function validateAllowedHosts(url: string | undefined, allowedHosts: string[] | undefined) { |
| 432 | if (typeof url === 'string') { |
no test coverage detected