Created
March 18, 2018 13:42
-
-
Save raduGaspar/cdcca4360e6d8a14309df935266ba837 to your computer and use it in GitHub Desktop.
HTTPS Redirect Express Middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = express() | |
server.use(function (req, res, next) { | |
if (req.host !== 'localhost' && req.get('X-Forwarded-Proto') === 'http') { | |
res.redirect(`https://${req.hostname}${req.url}`) | |
return | |
} | |
next() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment