-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
53 lines (42 loc) · 1.2 KB
/
server.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { enableProdMode } from '@angular/core';
import express from 'express';
import fs from 'fs';
import _ from 'lodash';
import { join } from 'path';
import 'zone.js/dist/zone-node';
enableProdMode();
const app = express();
const PORT = 6888;
const DIST_FOLDER = join(process.cwd(), 'dist');
const DIST_BROWSER_FOLDER = join(DIST_FOLDER, 'browser');
const { AppServerModuleNgFactory, LAZY_MODULE_MAP, ngExpressEngine, provideModuleMap }: any = fs.readFileSync('./dist/server/main');
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', DIST_BROWSER_FOLDER);
app.get('*.*', express.static(DIST_BROWSER_FOLDER, {
maxAge: '1y'
}));
app.get('app/*', (req: any, res: any) => {
res.type('html');
res.render('index', {
req
}, (_err: any, html: any) => {
res.send(_.unescape(html));
});
});
app.get('*', (req: any, res: any) => {
res.type('html');
res.render('index', {
req
}, (_err: any, html: any) => {
res.send(_.unescape(html));
});
});
app.listen(PORT, (): void => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});