Skip to content

Instantly share code, notes, and snippets.

@TravelingTechGuy
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TravelingTechGuy/5ef128528247ef630c93 to your computer and use it in GitHub Desktop.
Save TravelingTechGuy/5ef128528247ef630c93 to your computer and use it in GitHub Desktop.
Redirect from HTTP to HTTPS (in production)
//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