-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (49 loc) · 1.47 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
const express = require('express');
const config = require('./server/configure');
const mongoose = require('mongoose');
const flash = require('connect-flash');
const passport = require('passport'),
session = require('express-session'),
LocalStrategy = require('passport-local').Strategy,
ExpressValidator = require('express-validator');
var app = express()
app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(ExpressValidator({
errorFormatter: function(param, msg, value){
var namespace = param.split('.'),
root = namespace.shift(),
formParam = root;
while(namspace.length){
formParam += '[' + namespace.shift() + ']';
}return{
param: formParam,
msg: msg,
value: value
};
}
}));
app.use(flash());
app.use((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.login_err_msg = req.flash('login_err_msg');
res.locals.user = req.user || null;
next();
});
app.set('port', process.env.PORT || 3300);
app.set('Views', `${__dirname}/Views`);
app = config(app);
mongoose.connect('mongodb://nuutrini:[email protected]:25831/nuutrini');
mongoose.connection.on('open', ()=>{
console.log('Mongoose connected');
});
app.listen(app.get('port'), ()=>{
console.log(`Server up: http://localhost:${app.get('port')}`);
});