-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
69 lines (55 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
64
65
66
67
68
69
const express=require('express');
const bodyParser=require('body-parser');
const path=require('path');
var mongodb=require('mongodb');
var flash=require('connect-flash');
var validator=require('express-validator');
let session=require('express-session');
const app=express();
//Load view engine
app.set('views',path.join(__dirname,'views'));
app.set('view engine','pug');
//bodyParser middleware
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
//Loading static assets
app.use(express.static(path.join(__dirname,'public')));
//Express Session middleware
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { secure: true }
}));
//Expree-messages middleware
app.use(require('connect-flash')());
app.use(function (req, res, next) {
res.locals.messages = require('express-messages')(req, res);
next();
});
//Express-validator Middleware
app.use(validator({
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.get('/',function(req,res)
{
res.render('index');
});
let reviewRoute=require('./routes/review');
app.use('/review',reviewRoute);
var port=process.env.PORT || 8080;
app.listen(port,()=>console.log('Server started at port '+port));