-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (49 loc) · 1.93 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"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose"),
flash = require("connect-flash"),
passport = require("passport"),
LocalStratergy = require("passport-local"),
methodOverride = require("method-override"),
Campground = require("./Models/campground"),
Comment = require("./Models/comment"),
User = require("./Models/user")
seedDB = require("./seeds");
var commentRoutes = require("./Routes/comments"),
campgroundRoutes = require("./Routes/campgrounds"),
indexRoutes = require("./Routes/index");
//mongoose.connect("mongodb://localhost:27017/yelp_camp", {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true});
//mongoose.connect("mongodb+srv://Shubh:[email protected]/test?retryWrites=true&w=majority", {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true});
mongoose.connect(process.env.DATABASEURL);
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(__dirname + "/Public"));
app.use(methodOverride("_method"));
app.use(flash());
app.set("view engine", "ejs");
// seedDB();
app.use(require("express-session")({
secret: "Rusty is the best and cutest dog in the world",
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStratergy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use(function(req,res,next){
res.locals.error = req.flash("error");
res.locals.success = req.flash("success");
res.locals.currentUser = req.user;
next();
});
app.get("/",function(req,res){
res.render("landing");
});
app.use("/campgrounds",campgroundRoutes);
app.use("/campgrounds/:id/comments",commentRoutes);
app.use("/",indexRoutes);
app.listen(process.env.PORT || 3000,function(){
console.log("Server started");
});