-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (47 loc) · 1.53 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
var express=require("express");
var app = express();
var mongoose=require("mongoose");
var bodyParser=require("body-parser");
var Camp = require("./models/campSchema");
var Comment =require("./models/comment");
const { findById } = require("./models/campSchema");
var User = require("./models/user");
var methodOverride = require("method-override");
//ROUTES
var CampgroundRoutes = require("./Routes/Campground"),
CommentRoutes = require("./Routes/Comment"),
IndexRoutes = require("./Routes/Index");
var localStrategy = require("passport-local"),
passport = require("passport");
var DBURL=process.env.DB_URL ||"mongodb://localhost:27017/yelp_camp_practice";
mongoose.connect(DBURL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify:false
});
app.use(express.static("Public"));
app.use(bodyParser.urlencoded({extended:true}));
// PASSPORT CONFIGURE
app.use(require('cookie-session')({
secret:" ",
resave:false,
saveUninitialized:false
}));
app.locals.moment = require("moment");
app.use(passport.initialize());
app.use(passport.session());
//CURRENTUSER
app.use(function(req,res,next){
res.locals.currentUser=req.user;
next();
})
passport.use(new localStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use(methodOverride("_method"));
app.use(CampgroundRoutes);
app.use(CommentRoutes);
app.use(IndexRoutes);
app.listen(process.env.PORT || 3000,function(){
console.log("Server has started.....");
})