From 138ddfbed3746fe7cb03a1fcdc46fc610c098ec3 Mon Sep 17 00:00:00 2001 From: Adam Hovorka Date: Wed, 17 Jul 2019 19:32:57 -0600 Subject: Add basic WebSocket connection --- app.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 56b3b82..e026555 100644 --- a/app.js +++ b/app.js @@ -1,8 +1,8 @@ "use strict" -const http = require("http"); -const fs = require("fs"); -const ws = require("ws"); +const WebSocket = require("ws"); +const http = require("http"); +const fs = require("fs"); const Router = require("./lib/router"); const Static = require("./lib/static"); @@ -14,6 +14,7 @@ const PORT = Math.clamp(+process.env.PORT||8080, 1, 65535); const HOST = "0.0.0.0"; const server = http.createServer(); +const wss = new WebSocket.Server({server}); const stat = new Static("./public"); const app = new Router(); @@ -37,6 +38,11 @@ app.get("/hist.json", (req, res) => sj(res, [])); // req.pipe(fs.createWriteStream("./static/"+path[1])); //}); +wss.on("connection", ws => { + ws.on("message", msg => console.log("msg", msg)); + ws.send("hello"); +}); + server.on("request", (req, res) => { console.log(`${Date.now()} ${req.method} ${req.url}`); app.route(req, res) || stat.route(req, res); -- cgit v1.2.3-54-g00ecf