How to use the @angular/platform-server.renderModule function in @angular/platform-server

To help you get started, we’ve selected a few @angular/platform-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AngularClass / universal-sitegen / src / server.ts View on Github external
export function site (
  serverModuleFactory: Type<{}>,
  document: string,
  url: string = '/',
  config?: string | SiteGenConfig
) {
  // if (typeof config === 'string') {
  //   config = require.resolve(path.join(process.cwd(), config))
  // }

  // console.log('config here ', config)
  return renderModule(
    serverModuleFactory,
    {document, url}
  )
}
github asadsahi / AspNetCoreSpa / src / AspNetCoreSpa.Web / ClientApp / src / main.server.ts View on Github external
export default createServerRenderer(params => {
    const { AppServerModule, AppServerModuleNgFactory, LAZY_MODULE_MAP } = (module as any).exports;
    const options = {
        document: params.data.originalHtml,
        url: params.url,
        extraProviders: [
            provideModuleMap(LAZY_MODULE_MAP),
            { provide: APP_BASE_HREF, useValue: params.baseUrl },
            { provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
            { provide: COOKIES, useValue: params.data.cookies }
        ]
    };

    const renderPromise = AppServerModuleNgFactory
        ? /* AoT */ renderModuleFactory(AppServerModuleNgFactory, options)
        : /* dev */ renderModule(AppServerModule, options);

    return renderPromise.then(html => {
        return {
            html
        };
    });

});
github telerik / kendo-angular-universal-demo / aspnet_core_sample_application / ClientApp / src / main.server.ts View on Github external
export default createServerRenderer(params => {
  const { AppServerModule, AppServerModuleNgFactory, LAZY_MODULE_MAP } = (module as any).exports;

  const options = {
    document: params.data.originalHtml,
    url: params.url,
    extraProviders: [
      provideModuleMap(LAZY_MODULE_MAP),
      { provide: APP_BASE_HREF, useValue: params.baseUrl },
      { provide: 'BASE_URL', useValue: params.origin + params.baseUrl }
    ]
  };

  const renderPromise = AppServerModuleNgFactory
    ? /* AoT */ renderModuleFactory(AppServerModuleNgFactory, options)
    : /* dev */ renderModule(AppServerModule, options);

  return renderPromise.then(html => ({ html }));
});
github siegrainwong / ancorazor / src / client / src / main.server.ts View on Github external
const options = {
    document: params.data.originalHtml,
    url: params.url,
    extraProviders: [
      provideModuleMap(LAZY_MODULE_MAP),
      { provide: APP_BASE_HREF, useValue: params.baseUrl },
      { provide: "BASE_URL", useValue: params.origin + params.baseUrl }
    ]
  };

  // Bypass ssr api call cert warnings in development
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

  const renderPromise = AppServerModuleNgFactory
    ? /* AoT */ renderModuleFactory(AppServerModuleNgFactory, options)
    : /* dev */ renderModule(AppServerModule, options);

  return renderPromise.then(html => ({ html }));
});
github chrisjwalk / angular-cli-netcore-ngrx-starter / ClientApp / src / main.server.ts View on Github external
LAZY_MODULE_MAP,
  } = (module as any).exports;

  const options = {
    document: params.data.originalHtml,
    url: params.url,
    extraProviders: [
      provideModuleMap(LAZY_MODULE_MAP),
      { provide: APP_BASE_HREF, useValue: params.baseUrl },
      { provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
    ],
  };

  const renderPromise = AppServerModuleNgFactory
    ? /* AoT */ renderModuleFactory(AppServerModuleNgFactory, options)
    : /* dev */ renderModule(AppServerModule, options);

  return renderPromise.then((html) => ({ html }));
});
github angular / angular-cli / tests / legacy-cli / e2e / assets / webpack / test-server-app / app / main.ts View on Github external
import 'core-js/proposals/reflect-metadata';
import {platformDynamicServer, renderModule} from '@angular/platform-server';
import {AppModule} from './app.module';

AppModule.testProp = 'testing';

platformDynamicServer().bootstrapModule(AppModule);

renderModule(AppModule, {
  document: '',
  url: '/'
});
github angular / angular-cli / tests / e2e / assets / webpack / test-server-app / app / main.ts View on Github external
import 'core-js/es7/reflect';
import {platformDynamicServer, renderModule} from '@angular/platform-server';
import {AppModule} from './app.module';

AppModule.testProp = 'testing';

platformDynamicServer().bootstrapModule(AppModule);
renderModule(AppModule, {
  document: '',
  url: '/'
});
github kevinphelps / ng-static-site-generator / src / lib / renderer-page.ts View on Github external
    .mergeMap(() => renderModule(appServerModule, { url, document }))
    .map(html => ({ url, html: minifyHtml(html) }));
github kevinphelps / ng-static-site-generator / src / lib / generate-static-site.ts View on Github external
function renderPage(url: string, document: string) {
    return renderModule(appRendererModule, { url, document })
      .then(html => production ? minifyHtml(html) : html)
      .then(html => {
        const urlWithFilename = url.endsWith('/') ? `${url}index.html` : `${url}.html`;
        files.push({ path: urlWithFilename.substr(1), contents: html });
      });
  }
github kevinphelps / ng-static-site-generator / src / lib / generate-static-site.ts View on Github external
function renderPage(url: string, document: string) {
    const visitors = [
      removeInnerHtmlAttributes
    ];

    return renderModule(appRendererModule, { url, document })
      .then(html => transformHtml(html, visitors))
      .then(html => production ? minifyHtml(html) : html)
      .then(html => {
        const urlWithFilename = url.endsWith('/') ? `${url}index.html` : `${url}.html`;
        files.push({ path: urlWithFilename.substr(1), contents: html });
      });
  }