2018-06-21 19:42:51 +00:00
|
|
|
// require files
|
|
|
|
var express = require('express'),
|
|
|
|
http = require('http'),
|
|
|
|
https = require('https'),
|
|
|
|
settings = require('./config/settings'),
|
|
|
|
common = require('./dashboard/helper/common');
|
|
|
|
ini = settings.load(),
|
|
|
|
app = express(),
|
|
|
|
server = null;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2018-08-22 23:39:17 +00:00
|
|
|
var pathPrefix = '/sugarizer';
|
|
|
|
app.use(pathPrefix, require('path-prefix-proxy')(pathPrefix));
|
|
|
|
|
2018-06-21 19:42:51 +00:00
|
|
|
// Start listening
|
|
|
|
server.listen(ini.web.port,"0.0.0.0");
|
|
|
|
console.log("Sugarizer Server is listening on"+(ini.security.https ? " secure":"")+" port " + ini.web.port + "...");
|
|
|
|
|
|
|
|
//export app for testing
|
|
|
|
module.exports = app;
|