-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.js
96 lines (82 loc) · 2.69 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
var express = require('express');
var path = require('path');
var flash = require('connect-flash');
var bodyParser = require('body-parser');
var exphbs = require('express-handlebars');
var handlebars = require('handlebars');
var session = require('express-session');
var mongoose = require('mongoose');
mongoose.connect('mongodb://client:[email protected]:39267/glug');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('LOGGED | MongoDB Connected - ' + new Date());
});
// Add a variable for a new page here
var home = require('./routes/home');
var contact = require('./routes/contact-us');
var journey = require('./routes/journey');
var team = require('./routes/team');
var login = require('./routes/login');
var register = require('./routes/register');
var logout = require('./routes/logout');
var dashboard = require('./routes/dashboard');
var upcoming = require('./routes/upcoming');
var activities = require('./routes/activities');
var profile = require('./routes/profile');
var addmem = require('./routes/addmem');
var addevent = require('./routes/addevent');
// Init App
var app = express();
// Set Port
var port = process.env.PORT || 3000;
// Server
var server = require('http').Server(app).listen(port);
// View Engine
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', exphbs({defaultLayout:'main'}));
app.set('view engine', 'handlebars');
handlebars.registerHelper('ifCond', function(v1, v2, options) {
if(v1 === v2) {
return options.fn(this);
}
return options.inverse(this);
});
// BodyParser Middleware
app.use(bodyParser.json()); // to support JSON bodies
app.use(bodyParser.urlencoded({ extended: true })); // to support URL-encoded bodies
// Set Static Folder
app.use(express.static(__dirname + '/public'));
// Express Session
app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true
}));
//connect FLash
app.use(flash());
// Global Vars
app.use(function (req, res, next) {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.error = req.flash('error');
res.locals.user = req.user || null;
next();
});
// Use the variable for the new page here
app.use('/', home);
app.use('/contact', contact);
app.use('/journey', journey);
app.use('/team', team);
app.use('/register', register);
app.use('/login', login);
app.use('/logout', logout);
app.use('/dashboard', dashboard);
app.use('/upcoming', upcoming);
app.use('/activities', activities);
app.use('/profile', profile);
app.use('/addmem', addmem);
app.use('/addevent', addevent);
app.get('*', function(req, res){
res.render('404',{layout:false});
});