-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (36 loc) · 1.38 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
const express = require("express"),
mongoose = require("mongoose"),
User = require("./models/user"),
passport = require("passport"),
LocalStrategy = require("passport-local"),
passportLocalMongoose = require("passport-local-mongoose"),
cookieParser = require('cookie-parser'),
connectFlash = require('connect-flash');
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true,useUnifiedTopology: true,useCreateIndex :true})
.then(() => console.log('connection succesful'))
.catch((err) => console.error(err));
const app = express();
app.set("view engine","ejs");
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser(process.env.SESSION_SECRET));
app.use(require("express-session")({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: { maxAge : 4000000 }
}));
passport.use(User.createStrategy());
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use(connectFlash());
app.use(function (req, res, next) {
res.locals.user = req.user;
res.locals.isauth = req.isAuthenticated();
next();
});
app.use('/',require('./routes/auth'))
app.listen(process.env.PORT || 3000, function(){
console.log("listening to port")
});