From 4f876d5a96cc31ad496b6c18a826716e1254c350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 31 Jul 2019 10:47:24 -0400 Subject: [PATCH] add a redirect to https for production MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- back-end/routes/api-router.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/back-end/routes/api-router.js b/back-end/routes/api-router.js index 2b07335..363a56d 100644 --- a/back-end/routes/api-router.js +++ b/back-end/routes/api-router.js @@ -8,6 +8,15 @@ class APIRouter { /* for ElasticBeanstalk Load Balancer healthcheck */ app.use('/healthcheck', async (req, res) => res.send('OK')) + + /* redirect if not on https on prod */ + app.use(async (req, res, next) => { + if (req.get('x-forwarded-proto') == 'http') { + res.redirect('https://' + req.headers.host + req.url); + } else { + next() + } + }); } }