-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
103 lines (91 loc) · 2.92 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var express = require('express'),
bodyParser = require('body-parser'),
config = require('./config')(),
web = require('./app/routes/web'),
http = require('http'),
mongoose = require('mongoose'),
passport = require('passport'),
flash = require('connect-flash'),
session = require('express-session'),
cookieParser = require('cookie-parser');
//Create the application
var app = express();
var User = require('./api/models/user');
// API Routes
var api = require('./api/routes/api');
var users = require('./api/routes/users');
var tests = require('./api/routes/tests');
var questions =require('./api/routes/questions');
var results = require('./api/routes/results');
var courses = require('./api/routes/courses');
var sectors = require('./api/routes/sectors');
var comments = require('./api/routes/comments');
var conversations = require('./api/routes/conversations');
var messages = require('./api/routes/messages');
var notifications = require('./api/routes/notifications');
app.use(express.static(__dirname + '/app'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(session({
secret: 'Blah',
saveUninitialized: true,
resave: true,
expires: 360000
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
// configure passport
passport.serializeUser(function(user, done) {
/*console.log('serializing ' + user);*/
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.getUserById(id, function(err, user) {
/*console.log('deserializing ' + user);*/
done(err, user);
});
});
// Connect to MongoDB
mongoose.connect('mongodb://' + config.db.host + ':'
+ config.db.port + '/'
+ config.db.database,
function(err) {
if (err) {
console.log(err);
}
else {
console.log("Mongo connected");
}
}
);
// // Firebase connection
//
// var configData = {
// apiKey: "AIzaSyBT3-RmrTaIIMNRs9lKBPXReCIWNQQXXxU",
// authDomain: "unisexp-a1b2d.firebaseapp.com",
// databaseURL: "https://unisexp-a1b2d.firebaseio.com",
// projectId: "unisexp-a1b2d",
// storageBucket: "unisexp-a1b2d.appspot.com",
// messagingSenderId: "175197150875"
// };
// firebase.initializeApp(configData);
// console.log("firebase: "+firebase);
// Register web app routes
app.use('/', web);
// Register API routes
app.use('/api/', api);
app.use('/api/users/', users);
app.use('/api/tests/', tests);
app.use('/api/questions/', questions);
app.use('/api/results/', results);
app.use('/api/courses/', courses);
app.use('/api/sectors/', sectors);
app.use('/api/comments/', comments);
app.use('/api/conversations/', conversations);
app.use('/api/messages/', messages);
app.use('/api/notifications/', notifications);
//Serve app
http.createServer(app).listen(config.web.port);
console.log('The magic happens at ', config.web.port);