-
Notifications
You must be signed in to change notification settings - Fork 2
/
standalone
76 lines (67 loc) · 2.24 KB
/
standalone
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
#!/usr/bin/env node
const express = require('express');
const path = require('path');
const app = express();
const port = 8888;
const deploy = require('./deploy.json');
const moduleName = 'portal';
const controllers = require('./controllers');
const bodyParser = require('body-parser');
const externalAppTracker = require('./backend/external-app-tracker')(getDeploy('externalAppTracker'));
let staticFolder = 'themes/portal/static';
let template = 'themes/portal/templates';
let defaultPage = 'index';
let defaultPageNav = 'pages/index';
app.engine('ejs', require('ejs-locals'));
app.set('views', path.posix.join(__dirname, template));
app.set('view engine', 'ejs');
app.locals.pageEndContent = getDeploy( moduleName + '.pageEndContent') || getDeploy('pageEndContent') || '';
app.use('/', express.static(__dirname));
let limit = '1mb';
app.use(bodyParser.text({type: 'text/*', limit}));
app.use(bodyParser.json({type: 'application/json', limit}));
app.use(bodyParser.urlencoded({extended: true, limit}));
app.use(bodyParser.raw({limit}));
app.post('/api/create', controllers.create);
app.post('/api/get', controllers.get);
app.post('/api/update', controllers.update);
app.locals.standalone = {
api: {
create: 'api/create',
get: 'api/get',
update: 'api/update'
}
};
app.get('/' + defaultPage, (request, response) => {
response.render(defaultPageNav, {
module: '',
portal: staticFolder,
baseUrl: '/',
externalAppTracker
});
});
app.get('/*', (request, response) => {
response.redirect('/' + defaultPage);
});
app.listen(port, (err) => {
if (err) {
return console.log(JSON.stringify(err, null, '\t'));
}
console.log(`Server is listening on ${port}`);
});
// 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 ('There is no way to handle more than two deploy parameters. It is necessary to run through the framework');
}
} else {
return null;
}
}