-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
105 lines (90 loc) · 3.14 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
102
103
104
105
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var exphbs = require('express-handlebars');
var expressValidator = require('express-validator');
var flash = require('connect-flash');
var session = require('express-session');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var mongo = require('mongodb');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/eaglescout');
var db = mongoose.connection;
var login = require('./routes/login');
var scout = require('./routes/scout');
var admin = require('./routes/admin');
var account = require('./routes/account');
var utils = require('./utils');
var observationForm = require('./observationForm');
var userlist = require('./userlist');
var User = require('./models/user');
User.createAdminUserIfNotExists();
var app = express();
var hbs = exphbs.create({
defaultLayout: 'layout',
helpers: {
teamSummary: observationForm.getTeamSummaryHandlebarsHelper,
observationForm: observationForm.getObservationFormHandlebarsHelper,
editForm: observationForm.getEditObservationHandlebarsHelper,
table: observationForm.getTableHandlebarsHelper,
ranking: observationForm.getRankingHandlebarsHelper,
userlist: userlist.getUserListHandlebarsHelper
}
});
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true
}));
app.use(passport.initialize());
app.use(passport.session());
// app.use(expressValidator.validationResult({
// errorFormatter: function(param, msg, value) {
// var namespace = param.split('.')
// , root = namespace.shift()
// , formParam = root;
// while(namespace.length) {
// formParam += '[' + namespace.shift() + ']';
// }
// return {
// param : formParam,
// msg : msg,
// value : value
// };
// }
// }));
app.use(flash());
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;
res.locals.currentlyCurrentEvent = utils.getCurrentEvent() != null;
next();
});
app.use('/', login);
app.use('/account', account);
app.use('/scout', scout);
app.use('/scout/list', scout);
app.use('/scout/editobservation', scout);
app.use('/scout/teamranking', scout);
app.use('/scout/new', scout);
app.use('/admin', admin);
app.use('/admin/register', admin);
app.use('/admin/bulkimport', admin);
app.use('/admin/edituser', admin);
app.use('/admin/userlist', admin);
app.use('/admin/event', admin);
app.set('port', (3000));
app.listen(app.get('port'), function(){
console.log('Eaglescout started on port ' + app.get('port'));
});