-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (59 loc) · 1.86 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
require('dotenv').config()
const express = require('express');
const cors = require("cors");
const mongoose = require('mongoose');
const authRoutes = require('./routes/authRoutes')
var bodyParser = require('body-parser');
const answerRoute = require('./routes/answerRoute')
const cookieParser = require('cookie-parser');
const questionRoutes = require('./routes/questionRoutes');
const imageRoute = require('./routes/imageRoute');
const userRoutes = require('./routes/userRoutes');
const profileRoutes = require('./routes/profileRoutes');
const { checkIsVerified, checkJWT } = require('./middleware/authMiddleware');
const port = process.env.PORT || 4000;
const app = express();
app.use(
cors({
credentials: true,
})
);
app.use(express.json());
app.use(cookieParser());
// const URL = 'mongodb+srv://shreyaslshah:[email protected]/integration?retryWrites=true&w=majority';
// try {
// mongoose.connect(URL, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// })
// .then(app.listen(4000));
// console.log("Connected to DB !!");
// } catch (e) {
// console.log(e);
// throw e;
// }
// connect to database then setup express app
// mongoose.connect(process.env.MONGO_URI, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// })
// .then(app.listen(3000))
// .catch((err) => console.log(err));
// //testing db
mongoose.connect(process.env.MONGO_LINK , {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(app.listen(port))
.catch((err) => console.log(err));
app.get("/test", checkJWT, checkIsVerified, async (req, res) => {
return res.json({ 'user': req.userId });
})
app.use(authRoutes);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(authRoutes);
app.use('/questions', questionRoutes);
app.use('/users', userRoutes);
app.use(imageRoute);
app.use(answerRoute);
app.use(profileRoutes);