This repository has been archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (49 loc) · 1.44 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var fs = require('fs');
var jade = require('jade');
var config = require('./config');
var session = require("express-session");
var cookieparser = require("cookie-parser");
var MongoStore = require('connect-mongo')(session);
var router = require('./routes');
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'jade');
app.use(bodyParser.json());
//setUpMongoStore();
//middleware function for router
app.use(function(req,res,next){
//setUpSessionVars();
//move on to the next function
next();
});
app.use('/',router);
var server = app.listen(config.port, function() {
console.log("Listening on port " + config.port);
});
function setUpMongoStore() {
//the ingredients for making cookies
app.use(cookieparser());
//create a session hooked up to mongodb
app.use(session({
store: new MongoStore({
url: config.mongo.url
}),
secret: '1234567890QWERTYfd',
autoreconnect: true,
resave: true,
saveUninitialized: true,
}, function () {
console.log("db connection open");
}));
}
function setUpSessionVars() {
//if eventIndex hasn't been created in this session...
if(!req.session.eventIndex) {
//create an eventIndex and eventArray
req.session.eventIndex = 0;
req.session.eventArray = [];
}
}
module.exports = app;