-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (41 loc) · 1.21 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
var http = require('http'),
fs = require('fs'),
mongoose = require('mongoose'),
worker = require('./app/worker');
var app = require('./app/server'),
Continents = require('./lib/geodata/Continents'),
conf = require('./config/config');
var winston = require('winston'),
transportMongoDB = require('winston-mongodb').MongoDB
url = require('url');
//////////
// Init //
//////////
var uri = conf.get('database:uri');
mongoose.connect(uri);
console.log('database connection to ' + uri + '.');
Continents.init(function() {
start();
});
// Logger
var dbInfo = url.parse(uri);
winston.add(transportMongoDB, {
db: dbInfo.pathname.replace(/^\//, ''), // remove "/"
host: dbInfo.hostname,
port: parseInt(dbInfo.port)
});
////////////
// Daemon //
////////////
var period = conf.get('worker:period');
worker.cleaner(period);
console.log('worker will run every ' + period + ' seconds.')
console.log('Group will contains between ' + conf.get('group:min') + ' and ' + conf.get('group:max') + ' players.');
///////////
// Start //
///////////
var start = function() {
var port = conf.get('PORT');
app.listen(conf.get('PORT'));
console.log('Catalyz starts on port ' + port + '.');
};