-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (33 loc) · 1.02 KB
/
app.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
const express = require("express");
const path = require("path");
const WebSocket = require("ws");
const listen = require("./server");
const config = require("./config");
const app = express();
let expressWs = require("express-ws")(app);
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.static(path.join(__dirname, "public")));
app.get("/", function(req, res, next) {
res.render("index", {
res: JSON.stringify(listen.ports()),
socketAdress: `${config.ip}:${config.port}`,
});
});
app.get("/reset", function(req, res, next) {
listen.reset();
res.send(JSON.stringify(listen.ports()));
});
app.ws("/socket", function(ws, req, next) {});
listen.subscribe("test", () => {
expressWs.getWss().clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(listen.ports()));
}
});
});
app.listen(config.port, function() {
console.log("Started, port: 3000");
});
//module.exports = app;