-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
77 lines (60 loc) · 2.29 KB
/
server.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
const dotenv = require('dotenv');
dotenv.config({ path : './config/config.env'});
const env = process.env.NODE_ENV;
console.log(env);
const express = require("express");
const cors = require("cors");
const passport = require("passport");
const passportLocal = require("passport-local").Strategy;
const cookieParser = require("cookie-parser");
const bcrypt = require("bcryptjs");
const session = require("express-session");
const bodyParser = require("body-parser");
const app = express();
const PORT = process.env.PORT || 5000;
/** Require Routes */
const authRouter = require('./routes/auth')
const loanRouter = require('./routes/loan')
const contractRouter = require('./routes/contract')
const userRouter = require('./routes/user');
const reviewRouter = require('./routes/review');
const paymentRouter = require('./routes/payment');
const adminRouter = require('./routes/admin');
// Conncet to the database
const { mongoose } = require('./db/mongoose');
/******************************************* MIDDLEWARE ****************************************************/
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(
cors({
origin: "http://localhost:3000", // <-- location of the react app were connecting to
credentials: true,
})
);
app.use(
session({
secret: "secretcode",
resave: true,
saveUninitialized: true,
})
);
app.use(cookieParser("secretcode"));
app.use(passport.initialize());
app.use(passport.session());
require("./passportConfig")(passport);
//----------------------------------------- END OF MIDDLEWARE---------------------------------------------------
app.use('/api/auth', authRouter );
app.use('/api/loans', loanRouter);
app.use('/api/contract', contractRouter);
app.use('/api/user', userRouter);
app.use('/api/review', reviewRouter);
app.use('/api/payment', paymentRouter);
app.use('/api/admin', adminRouter);
// app.get("/user", (req, res) => {
// if(req.user)
// res.send(req.user);// The req.user stores the entire user that has been authenticated inside of it.
// else res.send("Unauthorized");
// });
//----------------------------------------- END OF ROUTES---------------------------------------------------
//Start Server
app.listen(PORT, () => console.log(`server running at port ${PORT}`))