Skip to content

Commit

Permalink
feat(aspnetcore-engine): support .NET Core version 3
Browse files Browse the repository at this point in the history
.NET Core version 3 users use the `completeHTML` property instead of `html` to avoid the below error.

```
InvalidOperationException: Globals is not supported when prerendering via UseSpaPrerendering().
Instead, your prerendering logic should return a complete HTML page, in which you embed any information you wish to return to the client.
```

.NET Core 3 usage examples
```
export default createServerRenderer(async params => {
  // Platform-server provider configuration
  const setupOptions: IEngineOptions = {
    appSelector: '<app-root></app-root>',
    ngModule: AppServerModule,
    document: params.data.originalHtml,
    request: params,
    providers: [
      ...
    ]
  };

  const { completeHTML } = await ngAspnetCoreEngine(setupOptions);
  return { html: completeHTML };
});
```
  • Loading branch information
alan-agius4 committed Jan 13, 2021
1 parent adbab25 commit 16c7c84
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/aspnetcore-engine/README.md
Expand Up @@ -7,7 +7,7 @@ This is an ASP.NET Core Engine for running Angular Apps on the server for server
## Installation

```bash
npm i --S @nguniversal/aspnetcore-engine
npm i --S @nguniversal/aspnetcore-engine @nguniversal/common-engine

This comment has been minimized.

Copy link
@patelhr

patelhr Jan 13, 2021

@alan-agius4
@nguniversal/common-engine

I think it will be @nguniversal/common.

This comment has been minimized.

Copy link
@alan-agius4

alan-agius4 Jan 13, 2021

Author Collaborator

Indeed

# or yarn install
```

Expand Down
3 changes: 2 additions & 1 deletion modules/aspnetcore-engine/src/interfaces/engine-options.ts
Expand Up @@ -6,9 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import { NgModuleFactory, StaticProvider, Type } from '@angular/core';
import { ɵRenderOptions as RenderOptions } from '@nguniversal/common/engine';
import { IRequestParams } from './request-params';

export interface IEngineOptions {
export interface IEngineOptions extends Pick<RenderOptions, 'publicPath' | 'inlineCriticalCss'> {
appSelector: string; // e.g., <app-root></app-root>
request: IRequestParams; // e.g., params
url?: string; // e.g., http://testhost.com
Expand Down
Expand Up @@ -7,6 +7,7 @@
*/

export interface IEngineRenderResult {
completeHTML: string;
html: string;
globals: {
styles: string;
Expand Down
2 changes: 2 additions & 0 deletions modules/aspnetcore-engine/src/main.ts
Expand Up @@ -49,6 +49,7 @@ function _getUniversalData(content: string, appSelector: string): IEngineRenderR
}

return {
completeHTML: content,
// tslint:disable-next-line: no-non-null-assertion
html: doc.querySelector(appSelector)!.outerHTML,
globals: {
Expand Down Expand Up @@ -76,6 +77,7 @@ export async function ngAspnetCoreEngine(options: Readonly<IEngineOptions>)
document: options.document || options.appSelector,
providers: [...(options.providers || []), getReqResProviders(options.request.origin, options.request.data.request)],
bootstrap: options.ngModule,
inlineCriticalCss: options.inlineCriticalCss,
};


Expand Down

0 comments on commit 16c7c84

Please sign in to comment.