-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (50 loc) · 1.92 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
var express = require("express")(),
mongoose = require("mongoose"),
bodyparser = require("body-parser"),
campground = require("./modules/campgrounds"),
comment = require("./modules/comments"),
passport = require("passport"),
User = require("./modules/user"),
localstrategy = require("passport-local"),
passportlocalmongoose = require("passport-local-mongoose"),
methodOverride = require("method-override"),
flash = require("connect-flash"),
cp = require("cookie-parser")
seedDB = require("./seeds");
var commentRoutes = require("./routes/comments"),
authRoutes = require("./routes/auth"),
campgroundRoutes = require("./routes/campgrounds");
//seedDB();
express.use(cp());
express.set("view engine", "ejs");
express.use(bodyparser.urlencoded({ extended: true }));
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://harish:harish16@ds131697.mlab.com:31697/yelpcamp", { useMongoClient: true })
//mongoose.connect("mongodb://localhost/yelpcamp", { useMongoClient: true });
express.use(require("express").static("public"));
express.use(methodOverride("_method"));
express.use(flash());
//PASSPORT CONFIGURATIONS
express.use(require("express-session")({
secret: "All You want to do is stay a minute ",
resave: false,
saveUninitialized: false,
}));
express.use(passport.initialize());
express.use(passport.session());
passport.use(new localstrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
express.use(function(req, res, next) {
res.locals.success = req.flash("success");
res.locals.error = req.flash("error");
res.locals.currentUser = req.user;
next();
})
//requiring routes
express.use("/campgrounds/:id/comments", commentRoutes);
express.use(authRoutes);
express.use("/campgrounds", campgroundRoutes);
express.listen(3000, function() {
console.log("Started YelpCamp server....");
})