-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (28 loc) · 932 Bytes
/
server.js
File metadata and controls
37 lines (28 loc) · 932 Bytes
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
require('zone.js/dist/zone-node');
require('reflect-metadata');
const express = require('express');
const fs = require('fs');
const { platformServer, renderModuleFactory } = require('@angular/platform-server');
const { ngExpressEngine } = require('@nguniversal/express-engine');
// Import the AOT compiled factory for your AppServerModule.
// This import will change with the hash of your built server bundle.
const { AppServerModuleNgFactory } = require(`./dist-server/main.bundle`);
const app = express();
const port = 8000;
const baseUrl = `http://localhost:${port}`;
// Set the engine
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
}));
app.set('view engine', 'html');
app.set('views', './');
app.use('/', express.static('./', {index: false}));
app.get('*', (req, res) => {
res.render('index', {
req,
res
});
});
app.listen(port, () => {
console.log(`Listening at ${baseUrl}`);
});