From 8bb949b2b36417feb71b7fd120055d922c0f13f9 Mon Sep 17 00:00:00 2001 From: teddit Date: Sun, 19 Sep 2021 20:48:51 +0200 Subject: [PATCH] redirect http => https before initializing reddit API (fixes #241) --- app.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 2aaefbb..076a661 100644 --- a/app.js +++ b/app.js @@ -106,6 +106,13 @@ app.use(express.static(`${__dirname}/static`)); app.set('views', './views'); app.set('view engine', 'pug'); +if (config.redirect_http_to_https) { + app.use((req, res, next) => { + if (req.secure) next(); + else res.redirect(`https://${req.headers.host}${req.url}`); + }); +} + const redditAPI = require('./inc/initRedditApi.js')(fetch); /* @@ -121,13 +128,6 @@ app.use('/', allRoutes); // The old routes //require('./routes')(app, redis, fetch, redditAPI); -if (config.redirect_http_to_https) { - app.use((req, res, next) => { - if (req.secure) next(); - else res.redirect(`https://${req.headers.host}${req.url}`); - }); -} - const cacheControl = require('./cacheControl.js'); cacheControl.removeCacheFiles();