-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
76 lines (48 loc) · 1.67 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
const express=require("express");
const app=express();
const mongoose=require("mongoose");
const expressLayouts=require("express-ejs-layouts");
const passport=require("passport");
const cors=require("cors");
// CORS POLICY
app.use(cors());
// SETTING VIEW ENGINE
app.use(expressLayouts);
app.use('/static',express.static('static'));
app.set("view engine","ejs");
// INCLUDING SESSIONS
const session=require("express-session");
const flash=require("connect-flash");
require("dotenv").config();
require("./Config/passport")(passport);
mongoose.connect(process.env.mongouri,{useNewUrlParser:true,useUnifiedTopology:false}).then(()=>{
console.log("Connection Successful");
}).catch(err=>{console.log(err)});
const PORT=process.env.PORT||3000;
// EXPRESS SESSION
app.use(session({
secret:'keyboard cat',
resave:false,
saveUninitialized:true
}));
// PASSPORT MIDDLEWARE
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
// SPECIFYING REQUEST HEADERS
app.use((req,res,next)=>{
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash("error_msg");
res.locals.error = req.flash("error");
res.locals.success=req.flash("success");
res.header('Cache-Control', 'nocache, no-store, max-age=0, must-revalidate');
res.header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');
res.header('Pragma', 'no-cache');
next();
});
app.use(express.urlencoded({extended:false}));
app.use('/',require("./Routes/index"));
app.use('/user',require("./Routes/user"));
require("./Config/google")(passport);
app.use('/google',require("./Routes/google"));
app.listen(PORT,console.log(`Server Started at ${PORT}`));