-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
60 lines (49 loc) · 1.62 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
51
52
53
54
55
56
57
58
59
60
const express = require("express")
const cors = require("cors")
const cookieParser = require('cookie-parser')
const path = require('path')
const expressLayouts = require('express-ejs-layouts')
const session = require('express-session')
const mongoose = require('mongoose')
const passport = require("passport")
const apiRouter = require("./routes/api")
const googleRouter = require('./routes/google')
const indexRouter = require("./routes/index")
const app = express()
const PORT = process.env.PORT || 3000
app.use(express.json())
app.use(cors())
const viewPath = path.join(__dirname, "./views");
//DB Config
mongoose.connect(dbKey,{
useNewUrlParser: true,
useUnifiedTopology:true,
useCreateIndex: true,
useFindAndModify: false
}).then(()=> {
console.log("MONGO DB CONNECTED!")
}).catch((e)=>console.log("Cannot Connect to Mongo",e))
//View Engine
app.use(expressLayouts);
app.set('view engine', 'ejs');
app.set("views", viewPath);
app.use(express.static("public"))
app.use(express.urlencoded({ extended:false }));
app.use(cookieParser())
app.use(session({
secret: 'THISISASESSIONSECRET',
saveUninitialized: true,
resave: true,
cookie: { maxAge: 60000 }
}))
//Passport Setup
app.use(passport.initialize())
app.use(passport.session())
app.use("/",indexRouter)
// app.use("/api/google", googleRouter)
// app.use("/users",userRouter)
app.use("/api",apiRouter)
app.listen(PORT, () => {
console.log(`Server up and running on port: ${PORT}.`);
})