Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force SSL on production #188

Merged
merged 8 commits into from
May 11, 2016
Merged

Force SSL on production #188

merged 8 commits into from
May 11, 2016

Conversation

edwardhorsford
Copy link
Contributor

This redirects requests to https.

Heroku has SSL built in, so for most prototypes, things should work as normal, except with SSL.

Note: I think this is a breaking change, since it requires production servers to have HTTPs set up.

@joelanman
Copy link
Contributor

Should it be a config setting so people can turn off if it breaks for them?

@edwardhorsford
Copy link
Contributor Author

Yes, just adding that now.

@@ -13,6 +13,9 @@ module.exports = {
// Enable or disable password protection on production
useAuth: 'true',

// Enable or disable HTTPs / SSL on production
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont think this is accurate - the code doesnt enable or disable HTTPS, it toggles a redirect

@@ -95,3 +95,11 @@ exports.findAvailablePort = function(app){
});

}

exports.forceHttps = function(req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could check req.secure instead:

http://expressjs.com/en/api.html#req.secure

@joelanman
Copy link
Contributor

We should check the docs to see if anything needs updating

@timpaul
Copy link
Contributor

timpaul commented May 4, 2016

Checked codebase for references to 'http'. Nothing in the docs, but I updated 2 links that should probably have been https all along.

@edwardhorsford
Copy link
Contributor Author

@joelanman I couldn't get res.secure to work. Once deployed to Heroku it always returned false. Sticking with current implementation as that works.

This page mentions: "Update: If you use a DNS redirect, req.secure may not work correctly and cause an infinite redirect loop. You should use req.headers['x-forwarded-proto'] !== 'https' instead in this case."

@robinwhittleton
Copy link
Contributor

@mcgoooo : does this look OK to you from a Node point of view?

@mcgoooo
Copy link

mcgoooo commented May 11, 2016

@robinwhittleton yeah looks good!

@joelanman joelanman merged commit 70f53bc into master May 11, 2016
@joelanman joelanman deleted the force_SSL branch May 11, 2016 17:10
@joelanman
Copy link
Contributor

great work @edwardhorsford 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants