-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·79 lines (63 loc) · 1.88 KB
/
server.js
File metadata and controls
executable file
·79 lines (63 loc) · 1.88 KB
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
var env = process.env.NODE_ENV || 'development'
, config = require ('./config').items[env]
, express = require('express')
, MongoStore = require('connect-mongo')(express)
, mongoose = require('mongoose')
, path = require('path')
, http = require('http')
, games = require('./app/controllers/games')
, users = require('./app/controllers/users')
, app = express()
, srvrconf = config.real_time_server
, server;
/**
*======================================
* ::: Mongoose Connect :::
*======================================
**/
mongoose.connect(config.db)
var sessionStore = new MongoStore({
url: config.db
});
/**
*======================================
* ::: Configure Express :::
*======================================
**/
app.configure(function () {
app.set('port', srvrconf.port);
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
secret: config.cookie_secret,
secure: true,
store: sessionStore
}));
app.use(express.static(path.join(__dirname, 'public')));
// app.use(express.static(path.join(__dirname, (env === 'production') ? 'public-built' : 'public')));
});
server = http.createServer(app).listen(app.get('port'), function () {
console.log("EXPRESS PORT:: " + app.get('port'));
});
/**
*======================================
* ::: Open Web Socket :::
* auth help from https://gist.github.com/bobbydavid/2640463
*======================================
**/
var io = require('socket.io').listen(server, {'log level':1});
/**
*======================================
* ::: Routes :::
*======================================
**/
app.get('/games', games.list);
app.get('/games/:slug', games.load);
app.post('/games', games.newGame);
app.post('/users', users.signup);
/**
*======================================
* ::: INIT :::
*======================================
**/
games.init(io,config);