-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwww
87 lines (77 loc) · 2.43 KB
/
www
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
const express = require('express');
const path = require('path');
const app = express();
const port = 8888;
const deploy = require('./deploy.json');
let staticFolder = 'themes/portal/static';
let template = 'themes/portal/templates';
let defaultPage = 'index';
let defaultPageNav = 'pages/index';
const default404 = '404';
app.engine('ejs', require('ejs-locals'));
app.set('views', path.posix.join(__dirname, template));
app.set('view engine', 'ejs');
// Emulate starting IONDV. Portal
function getDeploy(deployParam) {
if (deployParam) {
const getParam = deployParam.split('.');
if (getParam.length === 1) {
return deploy.globals[getParam[0]] ? deploy.globals[getParam[0]] : null;
} else if (getParam.length === 2){
return deploy.modules[getParam[0]].globals[getParam[1]] ?
deploy.modules[getParam[0]].globals[getParam[1]] : null;
} else {
throw ('It is not possible to process deploy parameters with a depth of more than two. Need to run through the framework');
}
} else {
return null;
}
}
const moduleName = 'portal';
app.locals.pageEndContent = getDeploy( moduleName + '.pageEndContent') || getDeploy('pageEndContent') || '';
app.use('/', express.static(__dirname, { maxAge: 86400000 }));
const pageTemplates = getDeploy( moduleName + '.pageTemplates');
const navigation = pageTemplates ? pageTemplates.navigation : null;
const externalAppTracker = require('./backend/external-app-tracker')(getDeploy('externalAppTracker'));
if(navigation) {
Object.keys(navigation).forEach((item) => {
app.get('/' + item, (request, response) => {
response.render(navigation[item], {
module: '',
portal: staticFolder,
baseUrl: '/',
externalAppTracker
});
});
});
} else {
app.get('/' + defaultPage, (request, response) => {
response.render(defaultPageNav, {
module: '',
portal: staticFolder,
baseUrl: '/',
externalAppTracker
});
});
}
app.get('/', (request, response) => {
response.redirect('/' + defaultPage);
});
app.get('/portal', (request, response) => {
response.redirect('/' + defaultPage);
});
app.use(function(request, response, next){
response.status(404);
response.render(default404, {
module: '',
portal: staticFolder,
baseUrl: '/'
});
});
app.listen(port, (err) => {
if (err) {
return console.log(JSON.stringify(err, null, '\t'));
}
console.log(`Server is listening on ${port}`);
});