forked from llaske/sugarizer-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sugarizer.js
44 lines (37 loc) · 1.07 KB
/
sugarizer.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
// require files
var express = require('express'),
http = require('http'),
https = require('https'),
settings = require('./config/settings'),
wait4db = require('./config/wait4db'),
common = require('./dashboard/helper/common');
ini = settings.load(),
app = express(),
server = null;
// wait for database
wait4db.waitConnection(ini, function() {
// init common
common.init(ini);
//configure app setting
require('./config/main')(app, ini);
// include api routes
require('./api/route')(app, ini);
// include dashboard routes
require('./dashboard/route')(app, ini);
// Handle https
if (ini.security.https) {
var credentials = common.loadCredentials(ini);
if (!credentials) {
console.log("Error reading HTTPS credentials");
process.exit(-1);
}
server = https.createServer(credentials, app);
} else {
server = http.createServer(app);
}
// Start listening
server.listen(ini.web.port);
console.log("Sugarizer Server is listening on"+(ini.security.https ? " secure":"")+" port " + ini.web.port + "...");
});
//export app for testing
module.exports = app;