-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
136 lines (115 loc) · 4.43 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
125
126
127
128
129
130
131
132
133
134
135
136
var http = require('http');
var async = require('async');
var express = require('express');
var debug = require('debug')('rideshare:app');
var config = require('./configs/server-configs/config');
var expressConfigs = require('./configs/server-configs/express-configs');
var configRedis = require('./configs/db-configs/config-redis');
var configMongodb = require('./configs/db-configs/config-mongodb');
var expressInstance = expressConfigs.configure();
var server = http.Server(expressInstance),
io = require('socket.io')(server);
var portNumber = config.config.production.server_port1;
server.listen(portNumber, function() {
debug('Server running on ' + portNumber);
function homeRender(req, pageType, responseCallback) {
debug('inside homeRender');
var argOne = 'index',
argTwo = {};
console.log(req.session.user);
if (req.session.user) {
argTwo = {
user_id: req.session.user.userId,
status: req.session.user.status,
display_name: req.session.user.displayName,
user_type: req.session.user.userType,
page_type: pageType
};
} else {
argTwo = {
user_id: null,
status: null,
display_name: null,
user_type: null,
page_type: pageType
};
}
responseCallback(argOne, argTwo);
};
async.parallel(
[
function(callback) {
configRedis.configure(callback);
},
function(callback) {
configMongodb.configure(callback);
}
],
function(err, results) {
if (err) {
debug(err);
} else {
debug(results);
expressInstance.get('/', function(req, res) {
debug('request to /');
homeRender(req, '', function(argOne, argTwo) {
res.render(argOne, argTwo);
});
});
expressInstance.get('/stats', function(req, res) {
debug('request to /stats');
homeRender(req, 'stats', function(argOne, argTwo) {
res.render(argOne, argTwo);
});
});
var routes = require('./controllers/routes');
io.on('connection', function(socket) {
socket.on('join', function (data) {
socket.join(data.userId); // We are using room of socket io
debug("User joined: "+data.userId);
});
routes.initialize(expressInstance, io, socket);
});
}
}
);
});
// var privateKey = fs.readFileSync('ssl-certs-1/my-ssl-certifications/host.key', 'utf8'),
// certificate = fs.readFileSync('ssl-certs-1/f5bbd28d4c33691b.crt', 'utf8'),
// ca1 = fs.readFileSync('ssl-certs-1/gd_bundle-g2-g1.crt');
// var credentials = {key: privateKey, cert: certificate, ca: [ca1]};
// https.createServer(credentials, expressInstance).listen(config.production.server_port2, function () {
// debug('Server running on ' + config.production.server_port2);
// async.parallel(
// [
// function(callback){
// configCassandra.configure(callback);
// },
// function(callback){
// configRedis.configure(callback);
// },
// function(callback){
// configMongodb.configure(callback);
// }
// ], function(err, results){
// if(err){
// debug(err);
// }else{
// debug(results);
// requirejs(['controllers/routes'],function(routes){
// routes.initialize(expressInstance); //dB
// });
// }
// }
// );
// });
//For redirecting from http to https
// var redirectApp = express();
// redirectServer = http.createServer(redirectApp).listen(config.production.server_port2, function(){
// redirectApp.use(function (req, res, next) {
// if (!req.secure) {
// return res.redirect('https://' + req.headers.host + req.url);
// }
// next();
// });
// });