-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
34 lines (26 loc) · 1.02 KB
/
Copy pathserver.ts
File metadata and controls
34 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { platformServer, renderModuleFactory } from '@angular/platform-server'
import { enableProdMode } from '@angular/core'
import { AppServerModuleNgFactory } from './dist/ngfactory/src/app/app.server.module.ngfactory'
import { readFileSync } from 'fs';
import * as express from 'express';
const config = require('./server.config.js');
const path = require('path');
enableProdMode();
const app = express();
let template = readFileSync(path.join(__dirname + '/dist/index.html')).toString();
app.engine('html', (_, options, callback) => {
const opts = { document: template, url: options.req.url };
renderModuleFactory(AppServerModuleNgFactory, opts)
.then(html => callback(null, html));
});
app.set('view engine', 'html');
app.set('views', 'src')
app.use(express.static(__dirname + '/dist'));
app.get('*', (req, res) => {
res.render('index', { req });
});
app.listen(config.server.port, () => {
console.log(`listening on http://localhost:${config.server.port}!`);
});