-
Notifications
You must be signed in to change notification settings - Fork 1
/
balloons.js
76 lines (65 loc) · 1.73 KB
/
balloons.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
var express = require('express')
, http = require('http')
, passport = require('passport')
, config = require('./config.json')
, init = require('./init')
, redis = require('redis')
, RedisStore = require('connect-redis')(express);
/*
* Instantiate redis
*/
if (process.env.REDISTOGO_URL) {
var rtg = require('url').parse(process.env.REDISTOGO_URL);
var client = exports.client = redis.createClient(rtg.port, rtg.hostname);
client.auth(rtg.auth.split(':')[1]); // auth 1st part is username and 2nd is password separated by ":"
} else {
var client = exports.client = redis.createClient();
}
var sessionStore = exports.sessionStore = new RedisStore({client: client});
/*
* Clean db and create folder
*/
init(client);
/*
* Passportjs auth strategy
*/
require('./strategy');
/*
* Create and config server
*/
var app = exports.app = express();
app.configure(function() {
app.set('port', process.env.PORT || config.app.port || 6789);
app.set('view engine', 'jade');
app.set('views', __dirname + '/views/themes/' + config.theme.name);
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.use(express.cookieParser(config.session.secret));
app.use(express.session({
key: "balloons",
store: sessionStore
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
});
/*
* Routes
*/
require('./routes');
/*
* Web server
*/
exports.server = http.createServer(app).listen(app.get('port'), function() {
console.log('Balloons.io started on port %d', app.get('port'));
});
/*
* Socket.io
*/
require('./sockets');
/*
* Catch uncaught exceptions
*/
process.on('uncaughtException', function(err){
console.log('Exception: ' + err.stack);
});