-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (48 loc) · 1.78 KB
/
app.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
const ENV = require('dotenv')
ENV.config()
var moment = require('moment')
var fs = require('fs')
var express = require('express')
var app = express()
app.use(express.static('static'))
app.set('view engine', 'ejs')
var mongoose = require('mongoose')
var bp = require('body-parser')
var expressSanitizer = require('express-sanitizer')
var methodOverride = require('method-override')
var passport = require('passport')
var localStrategy = require('passport-local')
var User = require('./models/user.js')
var commentRoutes = require('./routes/comments')
var campgroundRoutes = require('./routes/campgrounds')
var indexRoutes = require('./routes/index')
mongoose.connect('mongodb+srv://' + process.env.uname + ':' + process.env.password + '@cluster0-ji2ke.azure.mongodb.net?retryWrites=true&w=majority',
{ useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true }).then(() => {
console.log('Connected to DB Successfully')
}).catch(error => {
console.log("Error : " + error.message)
})
mongoose.set('useFindAndModify', false)
app.use(bp.urlencoded({ extended: true }))
app.use(methodOverride("_method"))
app.use(expressSanitizer())
// seed()
//====================PASSPORT CONFIG===============================
app.use(require('express-session')({
secret: 'IROC',
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
passport.use(new localStrategy(User.authenticate()))
passport.serializeUser(User.serializeUser())
passport.deserializeUser(User.deserializeUser())
app.use((req, res, next) => {
res.locals.currentUser = req.user
next()
})
app.use(indexRoutes)
app.use(campgroundRoutes)
app.use(commentRoutes)
app.listen(process.env.PORT);