This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
server.js
79 lines (58 loc) · 1.74 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
69
70
71
72
73
74
75
76
77
78
79
/*!
* Tabloro
* Copyright(c) 2014 Franky T
*
*/
/**
* Module dependencies
*/
var log = console.log;
log(process.env.NODE_ENV);
var fs = require('fs');
var mongoose = require('mongoose');
var express = require('express');
var passport = require('passport');
var config = require('config');
var R = require('ramda');
var EurecaServer = require('eureca.io').EurecaServer;
var app = express();
var port = process.env.PORT || 3000;
var server = require('http').createServer(app);
var eurecaServer = new EurecaServer({
allow: [ // Network client methods
'setId', 'spawnPlayer', 'kill', 'updateCursor',
'positionTile', 'dropTile', 'dragTiles', 'flipTile', 'toHand', 'fromHand', 'lock', 'unlock', 'ownedBy', 'releasedBy',
'updateStackCards', 'flipStack',
'spin',
'receiveChat', 'arrangeLayer'
]
});
log('attach eurecaServer', eurecaServer.version);
// attach eureca.io to our http server
eurecaServer.attach(server);
// Connect to mongodb
var connect = function () {
var options = { server: { socketOptions: { keepAlive: 1 } } };
mongoose.connect(config.db, options);
};
connect();
mongoose.connection.on('error', log);
mongoose.connection.on('disconnected', connect);
// Bootstrap models
fs.readdirSync(__dirname + '/app/models').forEach(function (file) {
if (~file.indexOf('.js')) require(__dirname + '/app/models/' + file);
});
// Bootstrap passport config
require('./config/passport')(passport, config);
// Bootstrap application settings
require('./config/express')(app, passport, eurecaServer);
// Bootstrap routes
require('./config/routes')(app, passport);
// Eureca Server config
require('eurecaserver')(eurecaServer);
server.listen(port);
log('Express app started on port ' + port);
/**
* Expose
*/
module.exports = app;