-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (42 loc) · 1.06 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
//
//
//
// main configs
global.init = require('./config.json');
global.init.web_url = `http://${global.init.base_url}:${global.init.port}${global.init.JSON_VIEW_PRE}`
// _id index
global.game_schemas = {};
// uuid index
global.games = {};
global.players = {
by_uuid: {},
by_socket_id: {}
};
const express = require('express');
const app = express();
require('./server/utils');
// main handers
const io_handler = require('./server/socket/');
const http_handler = require('./server/http/');
const connect_mongo = require('./bin/connect_mongo');
// create server
const server = require('http').Server(app);
const io = require('socket.io')(server);
// call main handlers
http_handler(app);
io_handler(io);
connect_mongo(function(err, status) {
if (err) {
console._error("mongo connection error!");
throw err;
}
// run the server
server.listen(global.init.port);
});
// if testing no log
if (process.env.NODE_ENV != 'test') {
require('./server/node_modules/logger');
} else {
console._log = console._error = function() {};
}
module.exports = app;