-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (23 loc) · 824 Bytes
/
Copy pathserver.js
File metadata and controls
26 lines (23 loc) · 824 Bytes
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
const
express = require("express"),
app = require("express")(),
pug = require("pug"),
http = require("http").Server(app),
io = require("socket.io")(http);
app.use("/bower_components", express.static(`${__dirname}/bower_components`));
app.use(express.static(`${__dirname}/dist`));
app.get("/", (req, res) => {
res.send(pug.renderFile(`${__dirname}/index.pug`));
});
io.on("connection", (socket) => {
io.emit("chat-enter", "system"); // @TODO getUser()
socket.on("chat-message", (text) => {
io.emit("chat-message", {content: text, author: "system"}); // @TODO getAuthor()
});
socket.on("disconnect", () => {
io.emit("chat-exit", "system");
});
});
http.listen(3000, () => {
console.log("listening on *:3000");
});