From 41f09e9473dc4a36fa3d3c315e68fc19e7b2fa0e Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Sun, 8 Dec 2019 23:47:24 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=F0=9F=8C=8D=20Checkpoint=20.?= =?UTF-8?q?/server.js:933874/382?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index d3bab03..c185ff3 100644 --- a/server.js +++ b/server.js @@ -22,6 +22,7 @@ try { app.use(express.static("public")); app.enable("trust proxy"); // needed for HTTP -> HTTPS redirect and successful test against req.secure +// redirect every route but /status as it's used by the ESP to send its status https://stackoverflow.com/a/49176816 const redirectToHTTPS = (req, res, next) => { if (req.secure) { // request was via https, so do no special handling @@ -31,11 +32,11 @@ const redirectToHTTPS = (req, res, next) => { res.redirect("https://" + req.headers.host + req.url); } }; +app.use("/", redirectToHTTPS); +app.use("/api", redirectToHTTPS); +app.use("/img", redirectToHTTPS); app.get("/", (req, res) => { - if (!req.secure) { - return res.redirect(["https://", req.get("Host"), req.baseUrl].join("")); - } res.sendFile(__dirname + "/views/index.html"); });