forked from meticulo3366/infinite_hangman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
124 lines (95 loc) · 3 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict';
//config file
var config = require('./config/config');
// global environment variable for fast mode
// fast mode disables all broadcasting
var isDisableBroadcast = true
if(process.env.DISABLE_BROADCAST){
console.log("$$$$$ SPEED MODE $$$$$")
isDisableBroadcast = false
}
// define globals
var express = require('express'),
io = require('socket.io'),
http = require('http'),
app = express(),
server = http.createServer(app),
io = io.listen(server),
path = require('path'),
favicon = require('static-favicon'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser');
/*var v8 = require('v8');
console.log(v8.getHeapStatistics())*/
// set an UNLIMITED NUMBER OF SOCKETS
http.globalAgent.maxSockets = Infinity
var puzzle = require('./gameLogic/gameLogic.js');
//set up the one instance of the hangman game, that everyone connects too
console.log("******** GAME INIT ***********")
console.log(puzzle.getCurrent() );
puzzle.newPuzzle()
console.log(puzzle.getCurrent() );
console.log(puzzle);
console.log("******************************")
// set up our JSON API for later
require('./routes/api')(app,puzzle);
//use redis for a message queue
//var redis = require('socket.io-redis');
//io.adapter(redis({ host: 'localhost', port: 6379 }));
// set up our socket server
require('./sockets/base')(io,puzzle,isDisableBroadcast);
// start the server
server.listen(config.server.port);
if (process.env.SIMPLE) {} else{
var redis = require('socket.io-redis');
io.adapter(redis({ host: config.redis.host, port: config.redis.port }));
};
// optional - set socket.io logging level
//io.set('log level', 1000);
//io.set('heartbeat interval', 100);
//io.set('destroy upgrade',false)
//io.set('log level', 1);
// view engine setup (for later)
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// middleware settings
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
// for dev
app.use(express.static(__dirname + '/angular-frontend/app/'));
// for production, do 'grunt --force' and then comment the line above
// and uncomment the line below
//app.use(express.static(__dirname + '/public'));
/// catch 404 and forwarding to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;