Skip to content

Instantly share code, notes, and snippets.

@hampusborgos
Last active August 31, 2018 09:39
Show Gist options
  • Save hampusborgos/07b409d0240cf89f2071 to your computer and use it in GitHub Desktop.
Save hampusborgos/07b409d0240cf89f2071 to your computer and use it in GitHub Desktop.
Force HTTPS on Heroku using Express
app.use(function (req, res, next) {
var sslUrl;
if (process.env.NODE_ENV === 'production' &&
req.headers['x-forwarded-proto'] !== 'https') {
sslUrl = ['https://hjnilsson.com', req.url].join('');
return res.redirect(sslUrl);
}
return next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment