/
app.js
57 lines (45 loc) · 1.39 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
'use strict';
const companyApi = require('./api/Company.api');
const headless = require('./api/Headless.api');
let config;
//dependencies
try {
config = require('./config')();
} catch(e) {
throw new Error(e+' Please copy config.example.js to config.js');
}
/**
* Start the application
*/
function start() {
let models = require('./models');
let app = companyApi.getExpress(config, models);
app.server = companyApi.startServer(app, function() {
if (null !== config.inactivityTimeout) {
app.inactivity = setTimeout(function() {
console.log('Exit because of inactivity timeout');
process.exit();
}, config.inactivityTimeout * 60000);
}
});
}
if (false === config.mongodb.init) {
start();
} else {
// The best way to initialize the database is to use the install.js script
// here we set default company name and contry because there is no way to set this
// on commmand line
let companyValues = {
name: 'Gadael',
country: 'FR' //TODO: get country code from file system?
};
companyApi.createDb(headless, config.mongodb.dbname, companyValues)
.then(company => {
// This is a first start, with db initialization
start();
})
.catch(err => {
// wee ignore the error because the database probably already exists
start();
});
}