From c1fc2a4e5faa3624a7456211d0864f4e1938ab5c Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 16 Apr 2020 08:34:01 +0200 Subject: [PATCH] HTTPS redirect --- qminingPublic/moodle-test-userscript | 2 +- server.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/qminingPublic/moodle-test-userscript b/qminingPublic/moodle-test-userscript index 2c815c8..f8d4bf2 160000 --- a/qminingPublic/moodle-test-userscript +++ b/qminingPublic/moodle-test-userscript @@ -1 +1 @@ -Subproject commit 2c815c8d20b6c25a4214d6118760d993f2287f36 +Subproject commit f8d4bf2a414d2973582c08bfa8b8b8f19389b2e9 diff --git a/server.js b/server.js index 1da6d70..26b7633 100755 --- a/server.js +++ b/server.js @@ -17,8 +17,6 @@ along with this program. If not, see . ------------------------------------------------------------------------- */ -process.stdout.write('\u001b[2J\u001b[0;0H') // console.clear() - const startHTTPS = true const isRoot = process.getuid && process.getuid() === 0 @@ -90,6 +88,19 @@ function exit (reason) { } const app = express() + +app.use(function (req, res, next) { + if (req.secure) { + next() + } else { + logger.DebugLog(`HTTPS ${req.method} redirect to: ${'https://' + req.headers.host + req.url}`, 'https', 1) + if (req.method === 'POST') { + res.redirect(307, 'https://' + req.headers.host + req.url) + } else { + res.redirect('https://' + req.headers.host + req.url) + } + } +}) // https://github.com/expressjs/cors#configuration-options app.use(cors({ credentials: true,