Skip to content

Instantly share code, notes, and snippets.

@hampusborgos
Created January 3, 2016 13:26
Show Gist options
  • Save hampusborgos/927ac6ff0847f0b558a8 to your computer and use it in GitHub Desktop.
Save hampusborgos/927ac6ff0847f0b558a8 to your computer and use it in GitHub Desktop.
Force specific domain and HTTPS on Heroku using Express
app.use(function (req, res, next) {
var newURL;
// If not on HTTPS, or not on the main domain, redirect
if (process.env.NODE_ENV === 'production' &&
(req.headers['x-forwarded-proto'] !== 'https' || req.headers.host !== 'hjnilsson.com')) {
newURL = ['https://hjnilsson.com', req.url].join('');
return res.redirect(newURL);
}
return next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment