-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
59 lines (48 loc) · 1.5 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
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose"),
methodOverride = require("method-override"),
indexRoute = require("./routes/index"),
postRoute = require("./routes/blog"),
commentRoute = require("./routes/comment"),
authRoute = require("./routes/auth"),
passport = require("passport"),
localStrategy = require("passport-local"),
passportLocalMongoose = require("passport-local-mongoose"),
User = require("./models/user"),
flash = require('connect-flash');
app.use(methodOverride("_method"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(flash())
app.use(
require("express-session")({
secret: "I am king of my thoughts 43223",
resave: false,
saveUninitialized: false
})
);
passport.use(new localStrategy(User.authenticate()));
app.use(passport.initialize());
app.use(passport.session());
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();
});
// Auth Part
app.use(indexRoute);
app.use(postRoute);
app.use(commentRoute);
app.use(authRoute);
mongoose.connect("mongodb://localhost/croud_head", { useNewUrlParser: true });
/* TODO :
(Optional) Add mailchimpu
*/
app.set("view engine", "ejs");
app.listen(3000, function() {
console.log("Server Started at Port 3000");
});