-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
62 lines (54 loc) · 1.43 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
61
62
const express = require("express");
const passport = require("passport");
const keys = require("./config/keys");
const cookieSession = require("cookie-session");
//ROUTES
const authRoute = require("./routes/auth");
//CHORE
const app = express();
const dotenv = require("dotenv");
const mongoose = require("mongoose");
//mongo connect
mongoose.connect(
"mongodb+srv://Shivansh:[email protected]/Clusters?retryWrites=true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true,
},
() => {
console.log("connected to db");
}
);
mongoose.set("useCreateIndex", true);
//
app.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: [keys.cookieKey],
})
);
app.use(passport.initialize());
app.use(passport.session());
require("./services/passport");
require("./routes/oauth")(app);
//
const {
verifyAccessToken
} = require("./webToken/jwt");
dotenv.config();
app.use(express.json());
//just a demo how to access private routes
app.get("/", verifyAccessToken, async (req, res, next) => {
res.send("accessing private route");
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send({
error: {
status: err.status || 500,
message: err.message,
},
});
});
//Route Middleware For Login And Signup routes
app.use("/api/user", authRoute);
app.listen(3000, () => console.log("server up and running"));