Skip to content

Instantly share code, notes, and snippets.

@asherccohen
Created December 17, 2019 08:49
Show Gist options
  • Save asherccohen/7af721e7191be0af2c91eade56b7ad62 to your computer and use it in GitHub Desktop.
Save asherccohen/7af721e7191be0af2c91eade56b7ad62 to your computer and use it in GitHub Desktop.
secure-redirect-middleware-heroku
const secureRedirectMiddleware = ({ dev }) => (req, res, next) => {
if(dev || req.headers['x-forwarded-proto'] === 'https'){
next();
} else {
res.redirect(301, `https://${req.hostname}${req.originalUrl}`);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment