-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (25 loc) · 851 Bytes
/
server.js
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
35
'use strict';
require('zone.js/dist/zone-node');
require('reflect-metadata');
const express = require('express');
const ngUniversal = require('@nguniversal/express-engine');
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main.bundle');
function angularRouter(req, res) {
res.render('index', {req, res});
}
const app = express();
app.engine('html', ngUniversal.ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', 'dist/browser');
app.get('/', angularRouter);
app.use(express.static(`${__dirname}/dist/browser`));
app.get('*', angularRouter);
app.listen(3000, () => {
console.log('Listening on port 3000');
});