-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (45 loc) · 1.4 KB
/
index.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
const express = require('express')
const path = require('path')
const config = require('./config');
const mainRouter = require('./routes/main');
const adminRouter = require('./routes/admin');
const PORT = process.env.PORT || 5001;
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const expressValidator = require('express-validator');
mongoose.connect(config.mongo);
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({
extended: false,
parameterLimit: 100000,
limit: '50mb'
}));
app.use(cookieParser());
app.use(session({ secret: 'keyboard cat' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());
app.use(expressValidator({
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.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use('/',mainRouter);
app.use('/admin',adminRouter);
app.listen(PORT, () => console.log(`Listening on ${ PORT }`))