-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (47 loc) · 1.23 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
const express = require('express')
const passport = require('passport')
const helmet = require("helmet")
const mongoose = require('mongoose')
const cookieSession = require('cookie-session')
const dotenv = require('dotenv')
dotenv.config()
require('./services/passportService')
const authRoutes = require('./routes/authRoutes')
const { Passport } = require('passport')
const app = express()
app.use(helmet())
app.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: [process.env.COOKIE_KEY]
})
)
app.use(passport.initialize())
app.use(passport.session())
app.use("/api/test", (req, res) => {
res.json({ "msg": "hello" })
})
app.use('/api/auth/google', authRoutes)
app.use("/api/logout", (req, res) => {
req.logout()
res.send(req.user)
})
app.use("/api/user", (req, res) => {
const data = req.body
res.json(req.user)
})
// app.use('/', (req, res) => {
// res.send("hello")
// })
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(
console.log("connnected to db"),
app.listen(5000, () => {
console.log("hello");
})
).catch((error) => {
console.log(error);
}
)