diff --git a/app.js b/app.js index 5128513..8cad533 100644 --- a/app.js +++ b/app.js @@ -2,6 +2,13 @@ const express = require('express') const app = express() const port = process.env.PORT || 3000 +app.use((req, res, next) => { + const forwardedProto = req.header("X-Forwarded-Proto") || req.protocol + console.log(`Incoming Protocol: ${forwardedProto}`) + forwardedProto === 'https' ? next() : res.redirect(301, 'https://' + req.headers.host + req.url) +}) + + app.get('/', (req, res) => { res.send('Hello World!') }) @@ -10,8 +17,3 @@ app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) }) -app.use((req, res, next) => { - const forwardedProto = req.headers["X-Forwarded-Proto"] || req.protocol - console.log(forwardedProto) - forwardedProto === 'https' ? next() : res.redirect('https://' + req.headers.host + req.url, 301) -}) \ No newline at end of file