-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 878 Bytes
/
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
const express = require("express");
const cors = require("cors");
const app = express();
const bodyParser = require("body-parser");
const server = require("http").Server(app);
const io = require("socket.io")(server);
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(
express.urlencoded({
extended: true,
})
);
io.on("connection", (socket) => {
console.log("A client connected");
socket.on("disconnect", () => {
console.log("A client disconnected");
});
});
app.get("/", (req, res) => {
res.send("Hey this is my API running 🥳");
});
app.post("/emit", (req, res) => {
console.log(req.body);
let lang = req.body.language;
io.emit("language", lang);
res.json({ msg: "Sent emit!" });
});
server.listen(5000, () => {
console.log("Express Socket.io server listening on port 5000");
});