-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
68 lines (59 loc) · 2.15 KB
/
server.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
var express = require('express')
, log = require('./jsutil').log
, util = require('util')
, _ = require('underscore')
, jade_browser = require('jade-browser')
, routes = require('./routes')
, http = require('http')
, path = require('path')
, mobileDetector = require('./middleware/mobileDetector')
, EventEngineHttpServer = require('./EventEngineHttpServer').EventEngineHttpServer
, Game = require('./GameServer.js').Game
, ChatServer = require('./ChatServer.js').ChatServer
, EventEngine = require('./EventEngine.js').EventEngine;
var app = express()
, eventEngine = new EventEngine()
, eventServer = new EventEngineHttpServer(eventEngine)
, server = http.createServer(app);
Game.create(eventEngine);
eventEngine.observe('client:game:new', function() {
Game.create(eventEngine);
});
var chatServer = new ChatServer(eventEngine);
app.configure(function(){
app.set('port', process.env.PORT || 8125);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
// app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(mobileDetector);
app.use(app.router);
app.use(require('less-middleware')({ src: __dirname + '/public' }));
app.use(jade_browser('/js/jade-templates', '**', {
root: __dirname + '/views',
namespace: 'jadeTemplates'
}));
// During development, server serves static files
// On AWS, static files are served from Nginx proxy
// (See https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html)
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', routes.index);
app.get('/game', routes.masterGame);
app.get('/game/:gameId', routes.game);
app.get('/jsutil.js', routes.js.jsutil);
app.get('/EventEngine.js', routes.js.EventEngine);
app.get('/debug/game/:gameId', routes.admin.game);
app.locals({
_: _
});
eventServer.listen(app);
server.listen(app.get('port'), function() {
console.log('Server running at http://localhost:' + app.get('port'));
});