Created
October 14, 2014 14:44
-
-
Save arcseldon/d7427075e69596a1adeb to your computer and use it in GitHub Desktop.
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
// author [email protected] | |
'use strict'; | |
module.exports = function (req, res, next) { | |
// we ARE deploying to Heroku. SSL termination happens at the load balancer, | |
// before encrypted traffic reaches your node app. It is possible to test | |
// whether https was used to make the request with req.headers['x-forwarded-proto'] === 'https'. | |
// See SOF answer by arcseldon: http://stackoverflow.com/a/22585754/1882064 | |
if ((req.headers['x-forwarded-proto'] !== 'https') && (process.env.NODE_ENV === 'production')) { | |
return res.redirect([ | |
'https://', | |
req.get('Host'), | |
req.url | |
].join('')); | |
} else { | |
next(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment