forked from aartichella/AmazonClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
91 lines (74 loc) · 2.35 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
/**
* Module dependencies.
*/
var express = require('express')
, http = require('http')
, path = require('path')
, favicon = require('static-favicon')
, logger = require('morgan')
, cookieParser = require('cookie-parser')
, bodyParser = require('body-parser')
, mongo = require("./routes/mongodb")
, ejs=require('ejs');
//Requiring the folders for routes
var firstPage= require('./routes/firstPage');
//URL for the sessions collections in mongoDB
var mongoSessionConnectURL = "mongodb://cmpeUser:[email protected]:10187/amazonDB";
var expressSession = require("express-session");
var mongoStore = require("connect-mongo")(expressSession);
var app = express();
/** Assigning Port **/
app.set('port', process.env.PORT || 3000);
/** View Engine Setup**/
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(favicon());
app.use(logger('dev'));
/** Parsing Url**/
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
/** Sessions**/
app.use(expressSession({
secret: 'cmpe273_teststring',
resave: false, //don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000,
store: new mongoStore({
url: mongoSessionConnectURL
})
}));
/**Handling Routing and Delegating Calls**/
//app.get('/', logIn.goToLogInPage);
/**Routing to the first page which asks the user his zip code**/
app.get('/firstPage', firstPage.firstPage);
/** Error Handling **/
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.render('error', {
message: err.message,
error: err
});
});
}
app.get('/firstPage', firstPage.firstPage);
app.use(function(err, req, res, next) {
res.render('error', {
message: err.message,
error: {}
});
});
/** Creating Server **/
mongo.connect(mongoSessionConnectURL, function(){
console.log('Connected to mongo at: ' + mongoSessionConnectURL);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
});