Created
January 3, 2016 13:26
-
-
Save hampusborgos/927ac6ff0847f0b558a8 to your computer and use it in GitHub Desktop.
Force specific domain and HTTPS on Heroku using Express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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