-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
68 lines (63 loc) · 2.08 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
const express = require("express");
const dotenv = require("dotenv");
dotenv.config();
const cors = require("cors");
const {
createUser,
loginUser,
isAuth,
userProfile,
getAllUsers,
} = require("./controller/user");
const {
contributeBook,
getBookDetails,
totalBookCount,
getBooksByQuery,
deleteBook,
updateBook,
} = require("./controller/book");
const { verifyToken, isSuperAdmin } = require("./middleware/authorization");
const multer = require("multer");
const { connectToMongoServer } = require("./connectToMongodb/connectToMongoDB");
const { sendMessage, getMessage, getConversations } = require("./controller/message");
const { app, server } = require("./socket/socket");
const PORT = process.env.PORT || 8080;
const storage = multer.memoryStorage();
const upload = multer({ storage });
const multiUpload = upload.fields([
{ name: "book", maxCount: 1 },
{ name: "image", maxCount: 1 },
]);
const corsOptions = {
origin: "*",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true, // Enable credentials (cookies, HTTP authentication) cross-origin
optionsSuccessStatus: 204,
exposedHeaders: "Authorization",
};
app.use(cors(corsOptions));
app.use(express.json());
// auth
app.post("/signup", createUser);
app.post("/login", loginUser);
app.get("/is-auth", verifyToken, isAuth);
// books
app.get("/contribute", verifyToken, contributeBook);
app.post("/contribute", multiUpload, verifyToken, contributeBook);
app.get("/total-books", verifyToken, isSuperAdmin, totalBookCount);
app.get("/books/:id", getBookDetails);
app.get("/book/genres", getBooksByQuery);
app.delete("/book/:id", verifyToken, deleteBook);
app.patch("/book/:id", multiUpload, verifyToken, updateBook);
// users
app.get("/all-users", verifyToken, isSuperAdmin, getAllUsers);
app.get("/user/:userId", verifyToken, userProfile);
// chat
app.get('/user/chat/:userId',verifyToken, getMessage)
app.post('/user/chat/:userId', verifyToken, sendMessage);
app.get('/chat/conversations', verifyToken, getConversations)
server.listen(PORT, () => {
connectToMongoServer();
console.log(`Listening On Port ${PORT}`);
});