Last active
August 29, 2015 14:27
-
-
Save TravelingTechGuy/5ef128528247ef630c93 to your computer and use it in GitHub Desktop.
Redirect from HTTP to HTTPS (in production)
This file contains hidden or 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
//redirect to https in production - add above all other routes | |
app.use('*', (req, res, next) => { | |
if(process.env.NODE_ENV !== 'development' && req.headers['x-forwarded-proto'] !== 'https') { | |
res.redirect(`https://${req.host}${req.url}`); | |
} | |
else { | |
next(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment