-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (44 loc) · 1.52 KB
/
index.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
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');
require('dotenv').config()
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.use(express.static('Public'))
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.use('/',require('./routes/routes'))
app.listen(process.env.PORT || 5005, function(){
console.log("listening to port")
});