-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
50 lines (41 loc) · 1.88 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
const fs = require('fs'),
path = require('path'),
http = require('http'),
DbList = require('./src/jsDbList'),
appList = JSON.parse(fs.readFileSync(path.join("config","appList.json"), {encoding: 'utf8'})),
Crypto = require('crypto-js'),
JsApplication = require('./src/jsApplication'),
jsExpressApplication = require('./src/jsExpressApplication.js'),
JsToken= require('./src/jsToken');
const Deferred = require("JQDeferred");
let secret = require('./config/secret');
// inizializza la dblist con tutte le DbInfo così che poi tutti possano ottenere da essa le connessioni
DbList.init({
encrypt: true,
decrypt: false,
fileName:path.join('config','dbList.json'), //rimuovere e cancellare in produzione
encryptedFileName: path.join('config','dbList.bin'), //questa è l'unica che deve rimanere
secret:secret
});
let port = process.argv[2] || process.env.PORT || 54471;
let GetMeta = require("./client/components/metadata/GetMeta");
GetMeta.setPath("./../../meta"); //all metadata must be stored here
//This must be executed as soon as possible
JsToken.assureMasterKey();
let expressApplication = jsExpressApplication.createExpressApplication();
//adds all applications
return Deferred.when(appList.map(appCfg=>{
//for every app configured creates a JsApplication running under "route" path configured
let application = new JsApplication();
return application.init(appCfg)
.then(()=>{
console.log("using route "+appCfg.route);
return expressApplication.use(appCfg.route,application.getApp());
});
}))
.then(()=>{
//runs the overall application
const server = http.createServer(expressApplication);
server.listen(port); //port is applied to external Application
console.log("server listening on port "+port);
});