-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (30 loc) · 865 Bytes
/
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
const express = require("express");
const cors = require("cors");
const app = express();
let rooms = [];
app.use(cors());
app.use(express.json());
app.post("/create-room", (req, res) => {
rooms.push(req.body);
res.status(200).send({ msg: "created" });
console.log(rooms)
});
app.get("/enter-room", (req, res) => {
let name = req.query.name;
let roomIndex = rooms.findIndex((room) => room.name == name);
if (roomIndex != -1) {
res.status(200).send(rooms[roomIndex]);
rooms.splice(roomIndex, 1);
console.log(rooms);
} else {
res.status(400).send({ msg: "NOT FOUND" });
}
});
app.listen(3000, () => {
console.log("\n");
console.log("========================================");
console.log("Server Running...");
console.log(`PORT: 3000`);
console.log("========================================");
console.log("\n");
});