2016-10-30 14:01:21 +00:00
|
|
|
var config = require("../config");
|
|
|
|
var Database = require("./database/database");
|
|
|
|
var utils = require("./utils");
|
|
|
|
var Socket = require("./socket");
|
2017-02-09 22:55:56 +00:00
|
|
|
var webserver = require("./webserver");
|
2014-04-07 00:33:49 +00:00
|
|
|
|
2014-12-14 03:43:05 +00:00
|
|
|
Object.defineProperty(Error.prototype, "toJSON", {
|
|
|
|
value: function() {
|
2014-12-27 02:47:40 +00:00
|
|
|
var str = this.message;
|
|
|
|
if(this.errors) {
|
|
|
|
for(var i=0; i<this.errors.length; i++)
|
|
|
|
str += "\n"+this.errors[i].message;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
2014-12-14 03:43:05 +00:00
|
|
|
},
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
2016-10-30 14:01:21 +00:00
|
|
|
process.on('unhandledRejection', (reason, promise) => {
|
|
|
|
console.trace("Unhandled rejection", reason);
|
2016-10-18 11:27:20 +00:00
|
|
|
});
|
|
|
|
|
2017-02-09 22:55:56 +00:00
|
|
|
const database = new Database();
|
2017-02-09 19:13:45 +00:00
|
|
|
|
2017-02-09 22:55:56 +00:00
|
|
|
utils.promiseAuto({
|
|
|
|
databaseConnect: database.connect(),
|
2016-03-04 19:40:02 +00:00
|
|
|
|
2017-02-09 22:55:56 +00:00
|
|
|
server: (databaseConnect) => {
|
2017-02-10 11:12:47 +00:00
|
|
|
return webserver.init(database);
|
2016-10-30 14:01:21 +00:00
|
|
|
},
|
2014-04-07 00:33:49 +00:00
|
|
|
|
2017-02-09 22:55:56 +00:00
|
|
|
socket: (server) => {
|
2016-10-30 14:01:21 +00:00
|
|
|
return new Socket(server, database);
|
|
|
|
}
|
|
|
|
}).then(res => {
|
2016-10-11 20:28:36 +00:00
|
|
|
console.log("Server started on " + (config.host || "*" ) + ":" + config.port);
|
2016-10-30 14:01:21 +00:00
|
|
|
}).catch(err => {
|
2016-10-11 20:28:36 +00:00
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
2016-10-30 14:01:21 +00:00
|
|
|
});
|