From ee362e89542ab71ee45a17f1c28443049dfca447 Mon Sep 17 00:00:00 2001 From: Hippo Date: Sun, 10 May 2020 23:03:14 +0530 Subject: [PATCH] Change host protocol depending on website and localhost If you're on localhost, your protocol (http vs https) takes precedence. If not, the other website's takes precedence, because otherwise you could end up being blocked by security --- server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 627be7a..5f6d536 100644 --- a/server.js +++ b/server.js @@ -39,7 +39,9 @@ app.use(renderer) app.get('/', (req, res) => { res.render('index', { - baseUrl: req.protocol + '://' + req.headers.host, + baseUrl: req.hostname.startsWith('localhost') + ? req.protocol + '://' + req.headers.host + : '//' + req.hostname, // auto choose http or https }) })