Created
January 29, 2018 12:26
-
-
Save ismcagdas/0cb446ec3c165b52579a5a4a165b7baf to your computer and use it in GitHub Desktop.
Acme.HeroShop - main.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'zone.js/dist/zone-node'; | |
import './polyfills.server'; | |
import { AppServerModule } from './app/app.server.module'; | |
import { enableProdMode } from '@angular/core'; | |
import { INITIAL_CONFIG } from '@angular/platform-server'; | |
// import { APP_BASE_HREF } from '@angular/common'; | |
import { createServerRenderer, RenderResult, BootFuncParams } from 'aspnet-prerendering'; | |
// import { ORIGIN_URL } from './app/shared/constants/baseurl.constants'; | |
// Grab the (Node) server-specific NgModule | |
// Temporary * the engine will be on npm soon (`@universal/ng-aspnetcore-engine`) | |
import { ngAspnetCoreEngine, IEngineOptions, createTransferScript } from '@nguniversal/aspnetcore-engine'; | |
enableProdMode(); | |
export default createServerRenderer((params: BootFuncParams) => { | |
// Platform-server provider configuration | |
const setupOptions: IEngineOptions = { | |
appSelector: '<app-root></app-root>', | |
ngModule: AppServerModule, | |
request: params, | |
providers: [ | |
// Optional - Any other Server providers you want to pass (remember you'll have to provide them for the Browser as well) | |
] | |
}; | |
return ngAspnetCoreEngine(setupOptions).then(response => { | |
// Apply your transferData to response.globals | |
response.globals.transferData = createTransferScript({ | |
someData: 'Transfer this to the client on the window.TRANSFER_CACHE {} object', | |
fromDotnet: params.data.thisCameFromDotNET // example of data coming from dotnet, in HomeController | |
}); | |
return ({ | |
html: response.html, | |
globals: response.globals | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment