-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
101 lines (86 loc) · 2.6 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
var express = require('express'),
app = express(),
path = require('path'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
config = require('./config/config.js'),
ConnectMongo = require('connect-mongo')(session),
mongoose = require('mongoose'),
passport = require('passport'),
FacebookStrategy = require('passport-facebook').Strategy,
rooms = [];
app.set('views', path.join(__dirname, 'views'));
app.engine('html', require('hogan-express'));
app.set('view engine', 'html');
mongoose.connect(config.dbURL, function(err) {
if(err != undefined){
console.log("MONGOOSE-CONNECT: " + err);
} else {
console.log("MONGOOSE-CONNECT: Database connection established");
}
});
app.use(express.static(path.join(__dirname, 'public')));
app.use(cookieParser());
var env = process.env.NODE_ENV || 'development';
setupENV(env);
// Initialze passport
app.use(passport.initialize());
app.use(passport.session());
require('./auth/passportAuth.js')(passport, FacebookStrategy, config, mongoose);
// Setup the routes
require('./routes/routes.js')(express, app, passport, config, rooms);
// app.listen(3000, confirmListen);
//
// function confirmListen(req, res, next){
// console.log("ChatCAT running on port 3000");
//
// }
// Create own http server for communication protocol
app.set('port', process.env.PORT || 3000);
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
require('./socket/socket.js')(io, rooms);
server.listen(app.get('port'), function(){
console.log('ChatCAT on: ' + config.host);
console.log("Mode " + env );
});
/*
* Setup environment middleware
*/
function setupENV(env){
if(env === 'development') {
// If NOT using express-session's 1.2.0 add saveUninitialize:true, resave:true to the hash
app.use(session({
secret:config.sessionSecret
}));
} else {
// Production
app.use(session({
secret:config.sessionSecret,
store: new ConnectMongo({
url:config.dbURL,
mongoose_connection:mongoose.connections[0],
stringify:true
}) // Store the DB connection in the user session
}));
}
}
// //Setting up and usering mongoose.
// var userShema = mongoose.Schema({
// username:String,
// password:String,
// fullname:String,
// });
// var Person = mongoose.model('users', userShema);
// var John = new Person({
// username:'johndoe',
// password:'johnwantstologin',
// fullname:'John Doe'
// });
// John.save(function(err){
// if (err != undefined) {
// console.log(err);
// } else {
// console.log("Done!");
// }
// });