prom = prom.then(_ => renderModuleFactory(AppServerModuleNgFactory, { document: index, url: route, extraProviders: [ provideModuleMap(LAZY_MODULE_MAP) ] })).then(html => writeFileSync(join(BROWSER_FOLDER, route, 'index.html'), html));
return function (filePath: string, options: { req: Request }, callback: (err: Error, html: string) => void) { let url: string = options.req.url; let html: string = outputCache[url]; if (html) { // return already-built page for this url console.log('from cache: ' + url); callback(null, html); return; } console.log('building: ' + url); if (!templateCache[filePath]) { let file = fs.readFileSync(filePath); templateCache[filePath] = file.toString(); } // render the page via angular platform-server let appModuleFactory = setupOptions.bootstrap[0]; renderModuleFactory(appModuleFactory, { document: templateCache[filePath], url: url }).then(str => { outputCache[url] = str; callback(null, str); }); };
return function ( filePath: string, options: { req: Request }, callback: (err: Error, html: string) => void) { const { req } = options; const routeUrl = req.url; let template = templateCache[filePath]; if (!template) { template = fs.readFileSync(filePath).toString(); templateCache[filePath] = template; } const { appModuleFactory } = setupOptions; const origin = getOrigin(req); // #docregion render // render the page renderModuleFactory(appModuleFactory, { document: template, url: routeUrl, extraProviders: [ { provide: APP_BASE_HREF, useValue: origin } ] }) .then(page => callback(null, page)); // #enddocregion render };
previousRender = previousRender.then(_ => renderModuleFactory(AppServerModuleNgFactory, { document: index, url: route, extraProviders: [ provideModuleMap(LAZY_MODULE_MAP) ] })).then(html => writeFileSync(join(fullPath, 'index.html'), html));
return function (filePath, options, callback) { renderModuleFactory(AppServerModuleNgFactory, { document: fs.readFileSync(filePath).toString(), url: options.req.url }).then(string => { callback(null, string); }); };
it('InjectionToken ngInjectableDef works', done => { renderModuleFactory(TokenAppModuleNgFactory, { document: '<token-app></token-app>', url: '/', }).then(html => { expect(html).toMatch(/>fromToken<\//); done(); }); });
it('@Optional() Self() resolves to @Injectable() scoped service', done => { renderModuleFactory(SelfAppModuleNgFactory, { document: '<self-app></self-app>', url: '/', }).then(html => { expect(html).toMatch(/>true<\//); done(); }); });
it('@Self() works in component hierarchies', done => { renderModuleFactory(HierarchyAppModuleNgFactory, { document: '<hierarchy-app></hierarchy-app>', url: '/', }).then(html => { expect(html).toMatch(/>false<\//); done(); }); });
it('works in AOT', done => { renderModuleFactory(BasicAppModuleNgFactory, { document: '<id-app></id-app>', url: '/', }).then(html => { expect(html).toMatch(/>0:0<\//); done(); }); });
app.engine('html', (_, options, callback) => { renderModuleFactory(AppServerModuleNgFactory, { // Our index.html document: template, url: options.req.url }).then(html => { callback(null, html); }); });