Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default createServerRenderer(params => {
const providers = [
{ provide: INITIAL_CONFIG, useValue: { document: '', url: params.url } },
{ provide: APP_BASE_HREF, useValue: params.baseUrl },
{ provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
];
return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
const state = moduleRef.injector.get(PlatformState);
const zone: NgZone = moduleRef.injector.get(NgZone);
return new Promise((resolve, reject) => {
zone.onError.subscribe((errorInfo: any) => reject(errorInfo));
appRef.isStable.first(isStable => isStable).subscribe(() => {
// Because 'onStable' fires before 'onError', we have to delay slightly before
// completing the request in case there's an error to report
setImmediate(() => {
resolve({
html: state.renderToString()
});
moduleRef.destroy();
});
});
export default createServerRenderer(params => {
const providers = [
{ provide: INITIAL_CONFIG, useValue: { document: '', url: params.url } },
{ provide: APP_BASE_HREF, useValue: params.baseUrl },
{ provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
];
return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
const state = moduleRef.injector.get(PlatformState);
const zone = moduleRef.injector.get(NgZone);
return new Promise((resolve, reject) => {
//zone.onError.subscribe((errorInfo: any) => reject(errorInfo));
appRef.isStable.first(isStable => isStable).subscribe(() => {
// Because 'onStable' fires before 'onError', we have to delay slightly before
// completing the request in case there's an error to report
setImmediate(() => {
resolve({
html: state.renderToString()
});
moduleRef.destroy();
});
});
export async function ngAspnetCoreEngine(options: Readonly)
: Promise {
if (!options.appSelector) {
const selector = `" appSelector: '<${appSelector}>' "`;
throw new Error(`appSelector is required! Pass in ${selector},
for your root App component.`);
}
// Grab the DOM "selector" from the passed in Template for example = "app-root"
appSelector = options.appSelector.substring(1, options.appSelector.indexOf('>'));
const compilerFactory: CompilerFactory = platformDynamicServer().injector.get(CompilerFactory);
const compiler: Compiler = compilerFactory.createCompiler([
{
providers: [
{ provide: ResourceLoader, useClass: FileLoader, deps: [] }
]
}
]);
const moduleOrFactory = options.ngModule;
if (!moduleOrFactory) {
throw new Error('You must pass in a NgModule or NgModuleFactory to be bootstrapped');
}
const extraProviders = [
...(options.providers || []),
getReqResProviders(options.request.origin, options.request.data.request),
test('using long form should work', async(() => {
const platform =
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: doc}}]);
platform.bootstrapModule(AsyncServerModule)
.then((moduleRef) => {
const applicationRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
return toPromise.call(first.call(
filter.call(applicationRef.isStable, (isStable: boolean) => isStable)));
})
.then(() => {
const str = platform.injector.get(PlatformState).renderToString();
expect(clearNgVersion(str)).toMatchSnapshot();
platform.destroy();
called = true;
});
}));
export function ngAspnetCoreEngine(
options: IEngineOptions
): Promise<{ html: string, globals: { styles: string, title: string, meta: string, transferData?: {}, [key: string]: any } }> {
options.providers = options.providers || [];
const compilerFactory: CompilerFactory = platformDynamicServer().injector.get(CompilerFactory);
const compiler: Compiler = compilerFactory.createCompiler([
{
providers: [
{ provide: ResourceLoader, useClass: FileLoader }
]
}
]);
return new Promise((resolve, reject) => {
try {
const moduleOrFactory = options.ngModule;
if (!moduleOrFactory) {
throw new Error('You must pass in a NgModule or NgModuleFactory to be bootstrapped');
}
"use strict";
const fs = require('fs');
require('core-js/client/core.js');
require('zone.js/dist/zone-node.js');
require('zone.js/dist/long-stack-trace-zone');
require('rxjs/Rx');
const co = require('@angular/core');
const ps = require('@angular/platform-server');
const prerenderModule = require('../tmp/app/module.prerender.server');
const document = fs.readFileSync('./public/prerender/index.html', 'utf-8');
co.enableProdMode();
const platform = ps.platformDynamicServer([{
provide: ps.INITIAL_CONFIG,
useValue: {
document: document,
url: 'http://localhost:8080'
}
}]);
platform.bootstrapModule(prerenderModule.AppModule).then(moduleRef => {
const state = moduleRef.injector.get(ps.PlatformState);
const appRef = moduleRef.injector.get(co.ApplicationRef);
appRef._isStable
.filter((isStable) => isStable)
.first()
.subscribe((stable) => {
try {
fs.mkdirSync('./tmp/prerender');
export function ngAspnetCoreEngine(
options: IEngineOptions
): Promise<{ html: string, globals: { styles: string, title: string, meta: string, transferData?: {}, [key: string]: any } }> {
options.providers = options.providers || [];
const compilerFactory: CompilerFactory = platformDynamicServer().injector.get(CompilerFactory);
const compiler: Compiler = compilerFactory.createCompiler([
{
providers: [
{ provide: ResourceLoader, useClass: FileLoader }
]
}
]);
return new Promise((resolve, reject) => {
try {
const moduleOrFactory = options.ngModule;
if (!moduleOrFactory) {
throw new Error('You must pass in a NgModule or NgModuleFactory to be bootstrapped');
}
getCompiler(): Compiler {
const compilerFactory: CompilerFactory = platformDynamicServer().injector.get(CompilerFactory);
return compilerFactory.createCompiler([
{providers: [{provide: ResourceLoader, useClass: FileLoader, deps: []}]}
]);
}