From 510d11b4574f2251c1408054511d8ede03da0de5 Mon Sep 17 00:00:00 2001 From: ian ramzy Date: Tue, 31 Mar 2020 17:07:03 -0400 Subject: [PATCH] server handles bad routing / params now --- public/js/chat.js | 10 ---------- server.js | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/public/js/chat.js b/public/js/chat.js index df67cbb..2deb8a8 100644 --- a/public/js/chat.js +++ b/public/js/chat.js @@ -663,16 +663,6 @@ pipVideo.addEventListener("leavepictureinpicture", () => { // function startUp() { - // strip url parameters - if (url.indexOf("?") > -1) { - window.location.href = url.split("?")[0]; - } - - // if no chat room provided go back to newroom - if (window.location.pathname === "/room") { - window.location.href = "/landing/newroom"; - } - // Redirect unsupported browsers if ( !isWebRTCSupported || diff --git a/server.js b/server.js index 7d84e16..9f78b9f 100644 --- a/server.js +++ b/server.js @@ -10,6 +10,7 @@ var http = require("http").createServer(app); var io = require("socket.io")(http); var path = require("path"); var public = path.join(__dirname, "public"); +const url = require("url"); // built-in utility // enable ssl redirect app.use(sslRedirect()); @@ -22,14 +23,27 @@ app.get("/newroom", function (req, res) { res.sendFile(path.join(public, "newroom.html")); }); +app.get("/room/", function (req, res) { + res.redirect("/"); +}); + app.get("/room/*", function (req, res) { - res.sendFile(path.join(public, "chat.html")); + if (Object.keys(req.query).length > 0) { + logIt("redirect:" + req.url + " to " + url.parse(req.url).pathname); + res.redirect(url.parse(req.url).pathname); + } else { + res.sendFile(path.join(public, "chat.html")); + } }); app.use(express.static("public")); function logIt(msg, room) { - console.log(room + ": " + msg); + if (room) { + console.log(room + ": " + msg); + } else { + console.log(msg); + } } // When a socket connects, set up the specific listeners we will use.