-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinalprep.js
102 lines (71 loc) · 2.23 KB
/
finalprep.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
var express = require('express');
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false });
var session = require('express-session');
var flash = require('connect-flash');
var cookieParser = require('cookie-parser');
var expressValidator = require('express-validator');
var path = require('path');
var exphbs = require('express-handlebars');
var cloudinary = require('cloudinary');
var multer = require('multer');
var cloudinaryStorage = require('multer-storage-cloudinary');
var go = express();
//include files from directory....
var logincontroller = require('./routes/logincontroller');
var adminlogincontroller = require('./routes/adminlogincontroller');
var uploadingadmin = require('./routes/uploadingadmin');
var user = require('./models/user');
//set up emplate engine
go.set('views', path.join(__dirname, 'views'));
go.engine('handlebars', exphbs({defaultLayout:'layout'}));
go.set('view engine', 'handlebars');
//static files
go.use(express.static((__dirname, 'public')));
//include files from routes folder
var users = require('./routes/logincontroller');
// BodyParser Middleware
go.use(bodyParser.json());
go.use(bodyParser.urlencoded({ extended: true }));
go.use(cookieParser());
//Express Session
go.use(session({
secret: 'secretsmmsmsmmm',
saveUninitialized : true,
resave : true
}));
//flash
go.use(flash());
//express-validator
go.use(expressValidator({
errorFormatter: function(param, msg, value) {
var namespace = param.split('.')
var root = namespace.shift()
var formParam = root;
while(namespace.length) {
formParam += '[' + namespace.shift() + ']';
}
return {
param : formParam,
msg : msg,
value : value
};
}
}));
//Global vars
go.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 included files
go.use(logincontroller );
go.use(adminlogincontroller );
go.use(uploadingadmin );
go.use( '/user',user);
//listen to port
var PORT = process.env.PORT;
go.listen(PORT);
console.log('All well listening to port ', PORT);