How to use the @angular/platform-server.INITIAL_CONFIG 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 marclaval / optimize-angular-app / scripts / prerender.js View on Github external
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');
      }