explore-services/sample-components/sampleComponent-rc4/src/main.node.ts

47 lines
1.2 KiB
TypeScript

// the polyfills must be the first thing imported in node.js
// import 'angular2-universal/polyfills'; // polyfills are moved to server.ts
// Angular 2 Universal
import {
REQUEST_URL,
ORIGIN_URL,
NODE_LOCATION_PROVIDERS,
NODE_HTTP_PROVIDERS,
ExpressEngineConfig
} from 'angular2-universal';
import { provideRouter } from '@angular/router';
import { APP_BASE_HREF } from '@angular/common';
// Application
import {App,routes} from './app/app.component';
import { disableDeprecatedForms, provideForms} from '@angular/forms';
export function ngApp(req, res) {
let baseUrl = '/';
let url = req.originalUrl || '/';
let config: ExpressEngineConfig = {
directives: [
App
],
platformProviders: [
{provide: ORIGIN_URL, useValue: 'http://localhost:3000'},
{provide: APP_BASE_HREF, useValue: baseUrl},
],
providers: [
{provide: REQUEST_URL, useValue: url},
NODE_HTTP_PROVIDERS,
provideRouter(routes),
disableDeprecatedForms(),
provideForms(),
NODE_LOCATION_PROVIDERS
],
async: true,
preboot: false // { appRoot: 'app' } // your top level app component selector
};
res.render('index', config);
}