Skip to content

Instantly share code, notes, and snippets.

@raduGaspar
Created March 18, 2018 13:42
Show Gist options
  • Save raduGaspar/cdcca4360e6d8a14309df935266ba837 to your computer and use it in GitHub Desktop.
Save raduGaspar/cdcca4360e6d8a14309df935266ba837 to your computer and use it in GitHub Desktop.
HTTPS Redirect Express Middleware
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