-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
95 lines (64 loc) · 1.96 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const express = require('express');
const authRoute = require('./routes/auth');
const homeRoute = require('./routes/home');
const allRoute = require('./routes/allUsers');
const friendRoute = require('./routes/friends');
const profileRoute = require('./routes/profile');
const commentRoute = require('./routes/comment');
const path = require('path');
const passport = require('passport');
const {connectMongoose} = require('./Models/user');
const Session = require('express-session');
const cookieParser = require('cookie-parser');
const {initializingPassport} = require('./passportConfig');
const flash = require('connect-flash');
const multer = require('multer');
const { log } = require('console');
connectMongoose();
initializingPassport(passport);
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.set('view engine','ejs');
app.use(express.static(path.join(__dirname,'public')));
app.use(express.static('public'));
app.use(cookieParser('keyboard cat'));
app.set('trust proxy', 1)
app.use(Session({
secret: 'keyboard cat',
resave: true,
saveUninitialized: true,
cookie: { maxAge : 600000000000000 },
}))
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use('/',authRoute);
app.use('/',homeRoute);
app.use('/',allRoute);
app.use('/',friendRoute);
app.use('/',profileRoute);
app.use('/',commentRoute);
app.get('/', async (req, res) => {
if (req.isAuthenticated()) {
const currentUser = req.user;
const userId = currentUser._id;
const data = await postModel.find({userId:userId});
console.log(data);
return res.render('home', { currentUser,data });
}
res.render('landingg.ejs');
});
app.get('/logout',(req,res)=>{
req.logOut((err)=>{
if(err){
console.log(err);
return res.redirect('/');
}
res.redirect('/');
})
})
const port = process.env.PORT || 4000;
app.listen(port,()=>{
console.log("Server Started at port 4000");
})