Project

General

Profile

1
// the polyfills must be the first thing imported in node.js
2
// import 'angular2-universal/polyfills'; // polyfills are moved to server.ts
3

    
4

    
5
// Angular 2 Universal
6
import {
7
  REQUEST_URL,
8
  ORIGIN_URL,
9
  NODE_LOCATION_PROVIDERS,
10
  NODE_HTTP_PROVIDERS,
11
  ExpressEngineConfig
12
} from 'angular2-universal';
13

    
14
import { provideRouter } from '@angular/router';
15
import { APP_BASE_HREF } from '@angular/common';
16

    
17
// Application
18
import {App,routes} from './app/app.component';
19
import { disableDeprecatedForms, provideForms} from '@angular/forms';
20

    
21
export function ngApp(req, res) {
22
  let baseUrl = '/';
23
  let url = req.originalUrl || '/';
24

    
25
  let config: ExpressEngineConfig = {
26
    directives: [
27
      App
28
    ],
29
    platformProviders: [
30
      {provide: ORIGIN_URL, useValue: 'http://localhost:3000'},
31
      {provide: APP_BASE_HREF, useValue: baseUrl},
32
    ],
33
    providers: [
34
      {provide: REQUEST_URL, useValue: url},
35
      NODE_HTTP_PROVIDERS,
36
      provideRouter(routes),
37
      disableDeprecatedForms(),
38
     provideForms(),
39
      NODE_LOCATION_PROVIDERS
40
    ],
41
    async: true,
42
    preboot: false // { appRoot: 'app' } // your top level app component selector
43
  };
44

    
45
  res.render('index', config);
46
}
(5-5/7)