Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created April 20, 2017 17:48
Show Gist options
  • Save brianleroux/9f01866f5a87852fbffe13025c4abc37 to your computer and use it in GitHub Desktop.
Save brianleroux/9f01866f5a87852fbffe13025c4abc37 to your computer and use it in GitHub Desktop.
express middleware for redirecting to http if a request to nginx came in from http
module.exports = function HTTPSRedirect(req, res, next) {
var env = process && process.env && process.env.NODE_ENV
if (env !== 'production' || req.headers['x-forwarded-proto'] === 'https' || req.url === '/health') {
next()
}
else {
res.redirect('https://' + req.hostname + req.url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment