forked from cyclic-software/starter-micro-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (26 loc) · 758 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
// https://leafletjs.com/examples/crs-simple/crs-simple.html
const express = require("express");
const app = express();
const http = require("http");
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
const port = 3000;
app.get("/", (req, res) => {
res.send("hello");
});
io.on("connect", (socket) => {
// console.log("a user connected");
io.emit("hello", "welcome");
socket.on("chat message", (msg) => {
console.log("message: " + msg);
io.emit("chat message", msg);
// socket.broadcast.emit("chat message", msg);
});
socket.on("disconnect", () => {
console.log("user disconnected");
});
});
server.listen(port, () => {
console.log(`listening on ${port}`);
});