Skip to content

Instantly share code, notes, and snippets.

@anthonydelgado
Created July 2, 2017 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonydelgado/4d19923b926da17468f09811b7bac806 to your computer and use it in GitHub Desktop.
Save anthonydelgado/4d19923b926da17468f09811b7bac806 to your computer and use it in GitHub Desktop.
Force SSL / HTTPS on heroku production server
function requireHTTPS(req, res, next) {
// The 'x-forwarded-proto' check is for Heroku
if (!req.secure && req.get('x-forwarded-proto') !== 'https' && process.env.NODE_ENV == "production") {
return res.redirect('https://' + req.get('host') + req.url);
}
next();
}
app.use(requireHTTPS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment