-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (52 loc) · 1.51 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
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require('express');
const mongoose = require('mongoose');
const keys = require('./config/keys');
const bodyParser = require('body-parser');
const passport = require('passport');
const expressValidator = require('express-validator');
const session = require('express-session');
const mongoStore = require('connect-mongo')(session);
const app = express();
// Connection to mlab (mongo db)
mongoose.connect(keys.mongoURI);
app.use(session({
secret: 'max',
saveUninitialized: false,
resave: false,
store: new mongoStore({
mongooseConnection: mongoose.connection
})
}));
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.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
// Passport Config
require('./config/passport')(passport);
// // Passport Middleware
app.use(passport.initialize());
app.use(passport.session());
// Route files
let users = require('./routes/users');
let trips = require('./routes/trips');
let passengers = require('./routes/passengers');
app.use('/users', users);
app.use('/trips', trips);
app.use('/passengers', passengers);
const PORT = process.env.PORT || 3000
app.listen(PORT)