-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (52 loc) · 1.63 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
63
64
65
const {Socket} = require("./Controller/Socket");
require("dotenv").config();
const cors = require("cors");
const mongoose = require("mongoose");
const express = require("express");
const port = 8001 || 8002 || process.env.PORT;
const app = express();
const server = require("http").createServer(app);
const io = require("socket.io")({
cors: [
"http://localhost:3000/",
"http://localhost:3001/",
process.env.FRONTEND_URL,
],
}).listen(server);
exports.io = io;
const UserController = require("./Controller/UserController");
app.use(
cors([
"http://localhost:3000/",
"http://localhost:3001/",
process.env.FRONTEND_URL,
])
);
app.use(express.json());
app.post("/Login", UserController.login);
app.post(
"/LoginVerifyAndCheckIfUserAlreadyLogged",
UserController.loginVerifyAndCheckIfUserAlreadyLogged
);
app.post("/Logout", UserController.logout);
app.post("/ChangePassword", UserController.changePassword);
app.post("/GetAllUsers", UserController.getAllUsers);
app.post("/GetAllUserMessages", UserController.getAllUserMessages);
app.post("/GetAllRooms", UserController.getAllRooms);
app.post("/GetOneUser", UserController.getOneUser);
app.post("/GetAllFriendsList", UserController.getAllFriendsList);
app.post("/UpdateUnreadMessage", UserController.updateUnreadMessage);
mongoose
.connect(
`mongodb+srv://${process.env.MONGOOSE_USERNAME}:${process.env.MONGOOSE_PASSWORD}@cluster0.cuw4ebp.mongodb.net/?retryWrites=true&w=majority`,
{}
)
.then(() => {
server.listen(port);
console.log("Listen To Port: " + port);
console.log("connected");
})
.catch((err) => {
console.log(err);
});
Socket(io);